in reply to search and replace from array values
#!/bin/perl5 use strict; use warnings; my @search = ("red", "orange", "blue"); my @replace = ("yellow", "black", "green"); my %replacements; @replacements{ @search } = @replace; my $string = q(red orange blue blue); for my $key (keys %replacements){ $string =~ s/$key/$replacements{$key}/ge; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: search and replace from array values
by Roy Johnson (Monsignor) on Dec 06, 2005 at 15:14 UTC |