On Tue, May 27, 2003 at 06:19:05PM +0200, Matthias Bauer wrote:
> 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?

Known bug. You should get a "modification of read-only value" error,
like you get if you do 'reverse 0, 1, 2, 3, 4, 5'.

Note the differences if you replace .. with a list, and whether or
not you use reverse or not:


    reverse 0 .. 5            654321
                              765432
                              876543

    0 .. 5                    123456
                              123456
                              123456

    reverse 0, 1, 2, 3, 4, 5  Modification of a read-only value attempted

    0, 1, 2, 3, 4, 5          Modification of a read-only value attempted



Abigail

Reply via email to