knexus,
It would be a good way to handle the problem, but I don't think you are
doing it quite right using conventional syntax.
my $large_scalar = 'a huge string like 64K or something';
modify_largescalar(\$large_scalar);
sub modify_largescalar {
my $scalar_ref = shift;
# Code to modify $$scalar_ref;
}
Your use of prototypes isn't helping (but maybe you need that for some other reason).
The thing is you are not creating refs until you are inside the sub - which means you are already copying the large scalar. You are using the fact that the elements of @_ are aliases to the variables and avoiding copying by assigning new variable names to references to the aliases. I do not know if this will avoid copying, but it certainly isn't conventional syntax. I also wouldn't worry about optimization of these large scalars unless they are truly large and/or you are calling these subs many times in a tight loop.
Hope this helps - L~R
Updated after CombatSquirrel pointed something out I took another look at perldoc perlsub and conferred with belg4mit in the CB.
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.