![]() |
|
laziness, impatience, and hubris | |
PerlMonks |
Re: lhs substr(): refs vs. scalarsby BrowserUk (Patriarch) |
on Oct 08, 2005 at 17:06 UTC ( #498434=note: print w/replies, xml ) | Need Help?? |
You know you can use substr as an lvalue or with a fourth parameter to avoid duplicating your big scalars. If you need to use unpack to decode small chunks of the buffer, or pack to overwrite small chunks, use them in conjunction with substr to avoid copying:
But be very sure that the size specified in substr, and the size of the result from pack match exactly, otherwise you will be expanding or shrinking your big scalar by the difference which will lead to nasty surprises. It may be better to use an intermediary variable here:
It is also possible (from 5.8.5 onwards) to set up an array of lvalue references to chunks of your scalar and then manipulate the individual chunks through indirection:
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
In Section
Seekers of Perl Wisdom
|
|