SPUG: refs to substrings contain lvalues

Yitzchak Scott-Thoennes sthoenna at efn.org
Sat Jul 31 23:51:45 CDT 2004

On Fri, Jul 30, 2004 at 08:50:37PM -0700, "Aaron W. West" <tallpeak at hotmail.com> wrote:
> $ perl -le '$x="stargazing";
> $y=\substr($x,0,4);
> print $y;
> $$y="sun";
> print $x;
> print $$y
> use Data::Dumper;
> print Dumper($y)'
> Output:
> LVALUE(0x10101570)
> sungazing
> sung
> cannot handle ref type 9 at /usr/local/lib/perl5/5.8.4/cygwin/Data/Dumper.pm
> line 158.

Whether that last print $$y gives "sung" is subject to change; in
development versions of perl it currently gives "sun", but there's
been some hesitation to make this change in maintenance versions.

Since 5.8.1 there's been a warning in perlfunc against relying on
it to stay the same.

More information about the spug-list mailing list