You can use both globals (package vars) and lexicals under use strict though globals need to be fully qualified ( $My::Mail::Server= "255.255.255.255";)
Though globals are usually (not always) the wrong way to go.
The idea of lexicals are that they only exist in a scope thereby limiting access. What local does is let you temporarily save a value for a package var. It's a runtime trick and my is (mostly) a compile time trick.
The lowdown is package vars exist in packages and any can be accessed from any package.
my vars exist in the scope they where declared in and cannot be accessed outside so you don't have to worry about other subs/modules etc clobbering your values.
You usually use local to save the value of $/ or $_ so you don't screw up code that calls your code. It has some other uses but that's one of the main one. There are probably a lot better explainations than mine and I'm sure if you do a search for lexical / package / global you will find a wealth of info here in the monestary.
UPDATEhere is a great FAQ on "Coping with Scoping" by
dominus. It's a far better explaination than mine.
-Lee
"To be civilized is to deny one's nature."
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.