in reply to Re^4: Constant value in anonymous sub (closures & aliases)
in thread Constant value in anonymous sub

My point was simply that it was a good by the book example of a closure. I stand by that statement.

Your issue seems to be more with how foreach makes its iterator variable an alias to the underlying object. I take it that you think it should be a copy, and not an alias? Well, that isn't very perl4-ish, and foreach has a long history. Just sticking with modern stuff, consider

foreach my $i ( @list ) { $i =~ s/foo/bar/g; } go_do_something(@list);

Would you expect the go_do_something() routine to get the unmodified values of @list, or would you expect the s/foo/bar/g transformation to have occured?

Replies are listed 'Best First'.
Re^6: Constant value in anonymous sub (closures & aliases)
by LanX (Saint) on Feb 24, 2010 at 14:56 UTC