in reply to Assignment changes handle?

The following code mimics what is going:
#!/usr/bin/perl use strict; use diagnostics; my @i = (5); my $n; map { $n = @i[1..0]; print $n.":"; my $u = "z"; } (6,2,3,4); print "outside:"; print $n;
This prints "4:z:z:z:outside:z" I think it is a bug in the interpreter. There is no $i[1] so it ends up assigning the last element of the list passed to map or the last literal value ("z") from the stack.
That's just my guess though.

Replies are listed 'Best First'.
Re^2: Assignment changes handle?
by Mugatu (Monk) on Mar 04, 2005 at 20:26 UTC

    It can be even further reduced to:

    my @i; map { my $n = @i[()]; print "n=$n\n"; "z"; } 1 .. 4;

    Update: this outputs:

    $ perl test n=4 n=z n=z n=z

    Interestingly, it does not have the same behavior in non-void context:

    my @i; print map { my $n = @i[()]; print "n=$n\n"; "z"; } 1 .. 4;

    Update: this outputs:

    $ perl test n=4 n=4 n=4 n=4 zzzz