develooper Front page | perl.perl5.porters | Postings from November 2008

Perl 5.8.x - bug with nested RE

Thread Next
From:
Alberto Simões
Date:
November 25, 2008 09:27
Subject:
Perl 5.8.x - bug with nested RE
Message ID:
492C357B.8090202@alfarrabio.di.uminho.pt
Hello

I am dealing with a strange substitution error, when doing subsitutions 
inside the evaluation portion of another substitution.

I have this small test:
-INPUT-------------------
$rules = <<EOS;

RULES
foo
bar
ENDRULES

RULES
foo

bar
ENDRULES
EOS

$rules =~ s{^RULES\n(.*?)^ENDRULES}{
              my $c = $1;
              $c =~ s/\n$/ARGH/;
              print ">>$c<<\n\n";
            }gems;
-EOF--------------------------

When running this, the first block of RULES get replaced correctly (the 
last newline from the block is substituted), and the output will be:

 >>foo
barARGH<<

For the second block, the newline at the end of the string will patch 
right in the blank line, outputting:

 >>fooARGH
bar
<<


It seems that this bug was fixed for 5.10.0, but still fails under perl 
5.8.9RC1.

If this is a bug (it seems to me, but I might be wrong, wouldn't be the 
first time), let me know if there is a workaround.

Thanks
Alberto





-- 
Alberto Simões - Departamento de Informática - Universidade do Minho
                  Campus de Gualtar - 4710-057 Braga - Portugal

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About