Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Search & Replace in an Array

by rubasov (Friar)
on Jan 27, 2010 at 12:20 UTC ( #819908=note: print w/ replies, xml ) Need Help??


in reply to Search & Replace in an Array

Have a look at on the Algorithm::Loops module on CPAN, especially on the Filter function.


Comment on Re: Search & Replace in an Array
Re^2: Search & Replace in an Array
by Saved (Beadle) on Jan 27, 2010 at 12:27 UTC
    Thanx, I was going to try a while loop, but knew there must be a better way. I appreciate your help.

      while or for loop will work fine but u need to use substitute command for substituting the pattern.

      my $length = scalar @arr; for (my $i =0; $i <= $length; $i++){ $arr[$i] =~ s/<pattern>/<pattern to be changed to>/g; } print "@arr";

        Or better (and more idiomatically) yet:
            s{MATCH}{REPLACEMENT}xmsg for @array;

        (Note that the //g regex modifier may or may not be what you need.)

        Update: Removed comments anent unavailability of documentation server.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (13)
As of 2014-12-26 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls