I want an anonymous scalar to which i can refer to from an unknown number of other scalars.
The only thing I can come up with (I'm not that familiar with PERL, yet) is this (example code):
$variable = "something";
$variableRef1 = \[ $variable ]->[ 0 ];
This makes it possible to change $variable without changing $$variableRef1 which is what I want.
I want to use this in a loop where i give $variable different values but want a copy of each value, but only 1 copy and an unknown number of references to this one copy.
How can I do this without constructing an anonymous array (or hash) and consume minimal time and memory?
Then later, if I change (in this example) $variableRef1 to refer to something else ($variable is also changed, so the refcount should be 0), PERL's garbage collection will free the now unused memory, right?
--
Alex
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.