http://qs321.pair.com?node_id=885299


in reply to Re^2: scope and declaration in local packages
in thread scope and declaration in local packages

I didn't realise that the function vs. variable "declaration" happens in different stages.

Function and variable declarations both happen at compile time. You wouldn't have been able to compile the function if that wasn't the case. How can it use a variable that doesn't exist?

Assignments, on the other hand, happen at run-time. That's why the following code works:

>perl -E"for (qw( a b )) { my $x = $_; say $x }" a b