go ahead... be a heretic | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
If you run your code through perl -MO=Xref mytest.pl, you'll get the following output...
The important part of all that is:
That's saying that $var is being declared in line 10, 21, and 34. ...and used in 27. This confirms what others have previously mentioned in this thread; that packages don't create their own lexical scopes. Files create lexical scope, and curly brackets do. So it's common to think of a package as its own lexical scope, since it's also common (though not a requirement) for packages to live alone in a file. But you can't rely on that logic because multiple packages in the same file reside in the same scope. Update: On a side note, I do think that B::Xref's output is a little misleading by saying, "Package (lexical) $var .....". It seems that it ought to say something more akin to "File (lexical) $var" or "Block (lexical) $var ..." I'm kind of interested in hearing the reason for why it does what it does. Dave In reply to Re: Scope, package, and 'my' variables
by davido
|
|