Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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]
[shmem]: missing is an euphemism
[Discipulus]: a piano et¨de can be harmfull, anyway
[shmem]: grandola vila morena *sing*

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2017-04-29 22:35 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (534 votes). Check out past polls.