I don't like to declare the same variable more than once.
sub read_cache {
our %CACHE;
...
}
sub write_cache {
our %CACHF;
...
}
Oops. It's so easy to slip... But on the other hand, you have to misspell the variable throughout all of
&write_cache, which usually isn't too probable. But for short routines--like get/set routines--it's a not too far-fetched scenario.
For those times I prefer to use
{
our %CACHE;
sub read_cache {
...
}
sub write_cache {
...
}
}
The only reason I want more education is that I learned about lexical and package variables as totally separate!!! and now they ain't... Which is cool, but also pretty bizarre.
I agree, it does indeed look like globals has become... something else. But you can relax--they haven't. They're still totally separate. What
our() does is to declare a lexical alias for the global variable.
Cheers,
-Anomo
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.