Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Subroutine performing operation on variable submitted to it...

by davido (Cardinal)
on Nov 24, 2011 at 07:41 UTC ( [id://939814]=note: print w/replies, xml ) Need Help??


in reply to Subroutine performing operation on variable submitted to it...

The answer is in perlsub.

$_[0] becomes an alias to the sub's parameter. In this case, that param is $item->{'title'}, so the change ripples back as you've experienced.

Do it this way:

sub strip_tags{ my $string = shift; # Or my $string = $_[0]; $string =~ s/<[^>]+>//gs; return $string; }

With that method you're making a copy of the string and working on it.


Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://939814]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-24 01:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found