Generally, from what I've seen so far Perl is rather good at managing memory efficiently and quickly.
Having the array persistent may speed things up if the function is being called ten thousands of times, but it also is an invitation to hogging memory, not to mention global variables just generally tend to lead to headaches. Creating a lexically scoped array a new slows things down a wee notch, but keeps the code clean and the memory footprint lean.
We're only talking 20,000 bytes of data here, that's not something I'd consider much of an array.
Two options you have if you really need the performance is passing around references instead, to keep things properly scoped without the overhead of array allocation; or using a closure like so:
{
my @not_global;
sub operate_on_not_global {
@not_global = whatever();
}
}
Bottome line: personally, I always take the defensive approach - I can always add dirty tricks later if my clean code is not fast enough, but if I start out dirty at the scratchpad, I'll never get a handle on things and end up with a big ball of mud.
Makeshifts last the longest.
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.