develooper Front page | perl.fwp | Postings from May 2003

Hidden state? Invisible closures?

Thread Next
From:
Matthias Bauer
Date:
May 27, 2003 09:19
Subject:
Hidden state? Invisible closures?
Message ID:
20030527161905.GB4329@faui1d.informatik.uni-erlangen.de
Hi everybody,
why is it that the following piece of code prints
three _different_ strings (in Perl 5.8)?

------8<------------------------
sub bla() {
  for my $i ( reverse 0 .. 5 ) {
    $i = $i + 1;
    print $i;
  }
  print "\n";
}

bla();
bla();
bla();
------>8------------------------

It seems as if the array created to hold the
returned AV of ''reverse 0..5`` is somehow
re--used in later invocations of blah(). 
Bug or feature or programming error?
If it's a feature, it would be nice if
''use warn 'all';`` would warn about it :-)

Best regards,

Matthias

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