If I have a scalar ref holding on to a big string, and take its length, will dereferencing it into length cause the string to be copied? I'm hoping since length is a builtin, it would not.
my $x = \" VERY VERY BIG STRING ....."; my $len = length( $$x );
If it were a sub, however, it would be
sub foo { my $s = shift; my $r = \$s; print "FOO ($r)\n" } my $X = "SOMESTRING"; my $O = \$X; my $R = \$X; print "NOTFOO ($R,$O)\n"; + foo( $$R );
outputs
NOTFOO (SCALAR(0x9393f8),SCALAR(0x9393f8)) FOO (SCALAR(0x9394a0))
EDIT, after some help from my friends One delightful thing I learned is that the @_ elements are _not_ copies. A sub does not have to copy.
sub foo { my $r = \$_[0]; print "FOO ($r)\n" } my $X = "SOMESTRING"; my $O = \$X; my $R = \$X; print "NOTFOO ($R,$O)\n"; + foo( $$R );
outputs
NOTFOO (SCALAR(0x1ac23e8),SCALAR(0x1ac23e8)) FOO (SCALAR(0x1ac23e8))

Original content restored below by GrandFather for reference.

If I have a scalar ref holding on to a big string, and take its length, will dereferencing it into length cause the string to be copied?

 my $x = \" VERY VERY BIG STRING ....."; my $len = length( $$x );

In reply to scalar reference and length by coyocanid

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.