Depends on what you mean by "global" and "local", since perl doesn't really have those categories.
Perl does have lexical (declared with "my" and, in 5.10, "state") and package (declared with "our", "use vars", or "local") variables. Package variables are sometimes called "global" variables, but file-scoped
lexical variables sometimes are too. I don't know which you mean.
For variables of the same name, whichever was most recently declared in the lexical scope will be
what's used, whether by print or anything else, when you just say $variable. (Where "declared"
means via "my", "state", or "our".)
You can explicitly get a package variable by qualifying with the package name it was declared in,
where the default package is "main" (with the empty string as an alias). So $main::var (aka $::var)
will get the package variable, even if $var is a lexical at that point in your code.
I hope this helps you at least enough to rephrase your question.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.