[Chicago-talk] Global variable behavior

Mithun Bhattacharya inzoik at yahoo.com
Wed Mar 3 18:20:26 PST 2010

Hi Everyone,

A piece of my code is behaving in a way I didn't expect and I was hoping someone could enlighten me as to why..

$ cat a.pl 
push @INC, '.';

our $c = 15;

require newbie;
$ cat newbie.pm 
package newbie;

print "first attempt: " . $c . "\n";
print "second attempt: " . $::c . "\n";

$ perl a.pl 
first attempt: 
second attempt: 15

The way I see it the our in a.pl should make it global across all namespaces. The second attempt does seem to say that did take place. What I am not sure is why the $c variable has become local in scope even though I haven't re-declared or redefined it in any way inside newbie.pm.

- Mithun

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20100303/bad6908d/attachment.html>

More information about the Chicago-talk mailing list