in reply to Regexp and substitution question
my $line = "One two three four five"; if (my @captures = $line =~ m/(one)\s(two)\s(three)\s(four)\s(five)/i) + { $captures[0] =~ s/one/ONE/i; print "$_: $captures[$_-1]\n" for 1..5; }
Note that uc might be more appropriate here. Any maybe split.
my $line = "One two three four five"; if (my @captures = split(' ', $line)) { $captures[0] = uc($captures[0]); print "$_: $captures[$_-1]\n" for 1..5; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regexp and substitution question
by bdalzell (Sexton) on Aug 28, 2010 at 14:27 UTC |