in reply to Re: Array of ($1, $2, ...) in replacement part of s///?
in thread Array of ($1, $2, ...) in replacement part of s///?
from perlvar:
so I wrote a test case:After a match against some variable $var: $` is the same as substr($var, 0, $-[0]) $& is the same as substr($var, $-[0], $+[0] - $-[0]) $' is the same as substr($var, $+[0]) $1 is the same as substr($var, $-[1], $+[1] - $-[1]) $2 is the same as substr($var, $-[2], $+[2] - $-[2]) $3 is the same as substr $var, $-[3], $+[3] - $-[3])
outputsuse strict; for my $regex (qr/(.)oo(.)ar(.)az/, qr/fo(.)barba(.)/) { my $str = "foobarbaz"; $str =~ s/$regex/ my @a; for my $index (1 .. $#+) { push @a, substr($str, $-[$index], $+[$index] - $-[$index]) +; } join "," , @a; /e; print "$str\n"; }
I'll have to remmember that one.f,b,b o,z
--
flounder
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Array of ($1, $2, ...) in replacement part of s///?
by diotalevi (Canon) on Jan 28, 2004 at 21:28 UTC | |
by flounder99 (Friar) on Jan 30, 2004 at 15:18 UTC |