http://qs1969.pair.com?node_id=55172

There are discoveries at every bend on the road to Perl enlightenment. One of the most distracting of these, for me, has been Perl's complex and diverse kinds of namespaces.

I came up with the following simple snippet, when I was experimenting to train myself to recognize (mostly-)namespace gotchas. Seasoned monks may not find this very surprising or interesting, but if you're new as I am, I think it's worth meditating on.

Read this closely:
Updated with comments.

#!/usr/bin/perl -w use strict; package First; # set the symbol: MULTIPLIER # and make $x equal to its value. use constant MULTIPLIER => 5*5; my $x = MULTIPLIER; package Second; # set a new symbol: if $x is defined in this context, # make this MULTIPLIER the same as the first, # otherwise "2". use constant MULTIPLIER => defined $x ? First::MULTIPLIER : 2; # easy! It's an error...it's 265...it's 50? Find out :-) print MULTIPLIER * $x, "\n";

Do you know what it will print? Do you know where the values came from?
mkmcconn

UPDATE: I just found this, where tilly shows a very similar behavior.

Update:
tilly it wrapped me in another knot, to add your

BEGIN{print MULTIPLIER; print "\n";}
And on the way there, I tried the following with amusing results (which proves tye's point made to me in CB, that the => operator is not just a cute comma:
BEGIN {print MULTIPLIER => "\n";}
And then, this from out of left field:
BEGIN {print MULTIPLIER * sub{return MULTIPLIER}, "\n";} # which really ought to be written as below to get # sane results (real obfuscation value there, # but not really a namespace issue) BEGIN {print MULTIPLIER * &{sub{return MULTIPLIER}}, "\n";}

Hopefully, I wouldn't even think of doing anything like these, in real life. How would you easily know where the whacky numbers are coming from?