Once again, you have correctly corrected me. :-) Thanks. I didn't happen to notice that OP was passing a reference, so, as you say, the issue was moot. On the other hand, whilst you are right that Perl passes by reference and I am grateful for the correction, the usual semantics of parameter usage does involve copies that can clobber a passed in tied scalar:

In this code sample, which compares the usage of a parameter array element directly ($_[0]) with one common usage of the array ($param = shift @_)

use strict; use warnings; { package TiedObject; sub TIESCALAR { my $sClass = shift; return bless([ @_ ], $sClass); } sub STORE {} sub FETCH { shift->[0]; } } my $sErr; tie $sErr, 'TiedObject', 5, "More data"; printTiedObject($sErr); sub printTiedObject { my $oErr = tied($_[0]); #does not copy scalar, prints out "...is tied to..." print "using \@_ directly\n"; if (defined($oErr)) { print "\$_[0] is tied to <$oErr>\n"; } else { print "\$_[0] is not tied"; } #copies scalar, prints out "..is not tied" print "\nafter \$param0 = shift \@_\n"; my $param0 = shift @_; $oErr = tied ($param0); if (defined($oErr)) { print "\$param0 is tied to <$oErr>\n"; } else { print "\$param0 is not tied\n"; } }

we get the following output

using @_ directly $_[0] is tied to <TiedObject=ARRAY(0x814ed48)> after $param0 = shift @_ $param0 is not tied

Best, beth


In reply to Re^3: Using a tied scalar as an in memory file by ELISHEVA
in thread Using a tied scalar as an in memory file by duncs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.