M
Mario D'Alessio
Here's an example script:
my $a = '1 foo';
my $b = 'foo bar';
if ( $a =~ /^\d+\s*(\w+)/ ) # line 1
{
$b =~ s/bar/$1/; # line 2
}
print $b, "\n";
I am using the capture buffer in line 1 in the regex in line 2. But it
doesn't
work. The capture buffer is cleared before the $1 substitution can take
place.
I would have thought that Perl would perform the $1 substitution in the line
2
before it "recognizes" the substitution command and clears the capture
buffers.
Please explain the order in which Perl processes line 1.
Do I have to "eval" line 2 to get it to work the way that I want without
having
to assign $1 to a temp var?
Thanks.
Mario
my $a = '1 foo';
my $b = 'foo bar';
if ( $a =~ /^\d+\s*(\w+)/ ) # line 1
{
$b =~ s/bar/$1/; # line 2
}
print $b, "\n";
I am using the capture buffer in line 1 in the regex in line 2. But it
doesn't
work. The capture buffer is cleared before the $1 substitution can take
place.
I would have thought that Perl would perform the $1 substitution in the line
2
before it "recognizes" the substitution command and clears the capture
buffers.
Please explain the order in which Perl processes line 1.
Do I have to "eval" line 2 to get it to work the way that I want without
having
to assign $1 to a temp var?
Thanks.
Mario