[Israel.pm] use constant and our

Shmuel Fomberg semuelf at 012.net.il
Wed Mar 4 14:07:10 PST 2009


Hi All.

Today I've seen a weird behavior in a program. I had something like:

our @list = qw{one two three};

use constant VAR => {
    key => "value",
    map( { ( $_ => 16 ) } @list ),
    key2 => "value2",
};

To my surprise, VAR contained only key and key2.
I theorized that it is because "use constant" is set in compile time, 
and @list is empty in that time. @list is populated in run-time, but 
that is too late for VAR.

Am I right or is there other reason for this?

Tested on Perl 5.6.

Shmuel.



More information about the Perl mailing list