develooper Front page | perl.perl5.porters | Postings from January 2004

Strange interaction between /g and @-

Thread Next
From:
Gisle Aas
Date:
January 13, 2004 02:29
Subject:
Strange interaction between /g and @-
Message ID:
lr3cakm9aj.fsf@caliper.activestate.com
Where does all these undefs come from?

[gisle@ask gisle]$ perl -we '$_ = "f\n"; /f/g; use Data::Dumper; print Dumper(\@-, \@+);'
$VAR1 = [
          '0',
          undef,
          undef,
          undef,
          undef,
          undef,
          undef
        ];
$VAR2 = [
          '1'
        ];

When we match against "fa" instead of "f\n" it is all normal:

[gisle@ask gisle]$ perl -we '$_ = "fa"; /f/g; use Data::Dumper; print Dumper(\@-, \@+);'
$VAR1 = [
          '0'
        ];
$VAR2 = [
          '1'
        ];

[gisle@ask gisle]$ perl -v
This is perl, v5.8.2 built for i686-linux


In the real app perl runs out of memory when I access @- after a /g
match, but I have not yet been able to reproduce that in a smaller
test case.  But perl-5.8.0 seems to do that on the first example
above.  Any ideas what's wrong?

--Gisle

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