Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: scope and declaration in local packages

by december (Pilgrim)
on Jan 31, 2011 at 13:24 UTC ( [id://885267] : note . print w/replies, xml ) Need Help??


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

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

I used the "ref instance constructor" this time because I've seen it around and it seemed like a nice extra feature to have. I doubt if it's really useful to my code, though... Probably it's cleaner without.

Replies are listed 'Best First'.
Re^3: scope and declaration in local packages
by ikegami (Patriarch) on Jan 31, 2011 at 15:50 UTC

    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