Saved has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Search & Replace in an Array
by BioLion (Curate) on Jan 27, 2010 at 12:11 UTC

    What have you tried?

    The simplest approach, you could use a for loop, test each element in turn and change it if it matches your criteria.

    Just a something something...
Re: Search & Replace in an Array
by ikegami (Patriarch) on Jan 27, 2010 at 18:53 UTC

    A generic form for a generic question:

    for (@array) { if (condition($_)) { $_ = transform($_); } }
    The above can also be written as
    $_ = transform($_) for grep condition($_), @array;
    For example,
    my @array = qw( John Jake and Jasper ); $_ = uc($_) for grep /^a/, @array; print("@array\n"); # John Jake AND Jasper
Re: Search & Replace in an Array
by rubasov (Friar) on Jan 27, 2010 at 12:20 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";
Re: Search & Replace in an Array
by Anonymous Monk on Jan 27, 2010 at 12:20 UTC