in reply to Re: Search & Replace in an Array
in thread Search & Replace in an Array

Thanx, I was going to try a while loop, but knew there must be a better way. I appreciate your help.

Replies are listed 'Best First'.
Re^3: Search & Replace in an Array
by snape (Pilgrim) on Jan 27, 2010 at 15:26 UTC

    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.