coyocanid has asked for the wisdom of the Perl Monks concerning the following question:
If it were a sub, however, it would bemy $x = \" VERY VERY BIG STRING ....."; my $len = length( $$x );
outputssub 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 );
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.NOTFOO (SCALAR(0x9393f8),SCALAR(0x9393f8)) FOO (SCALAR(0x9394a0))
outputssub foo { my $r = \$_[0]; print "FOO ($r)\n" } my $X = "SOMESTRING"; my $O = \$X; my $R = \$X; print "NOTFOO ($R,$O)\n"; + foo( $$R );
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 );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: scalar reference and length
by choroba (Cardinal) on Oct 29, 2019 at 22:51 UTC | |
Re: scalar reference and length
by rjt (Curate) on Oct 29, 2019 at 22:53 UTC |