Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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.

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://819908]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2018-03-22 10:18 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (273 votes). Check out past polls.