in reply to foreach funny business

Creating a reference to a constant must make a copy of it, because the following works without error too: (Perl v5.6.1)

foreach my $thing (qw/foo bar baz/) { print "$thing -> "; my $c = chop ${\$thing}; print " $thing,$c\n"; }

Replies are listed 'Best First'.
Re^2: foreach funny business
by shmem (Chancellor) on Jun 29, 2006 at 20:38 UTC
    My 5.6.1 does die:
    perseus [gm] 22:26 /home/gm > perl -v This is perl, v5.6.1 built for i386-openbsd Copyright 1987-2001, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using `man perl' or `perldoc perl'. If you have access to + the Internet, point your browser at http://www.perl.com/, the Perl Home Pa +ge. perseus [gm] 22:26 /home/gm > perl foreach my $thing (qw/foo bar baz/) { print "$thing -> "; my $c = chop ${\$thing}; print " $thing,$c\n"; } Modification of a read-only value attempted at - line 3. foo -> perseus [gm] 22:26 /home/gm >

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re^2: foreach funny business
by Sidhekin (Priest) on Jun 29, 2006 at 20:39 UTC

    Same bug, I guess ... and it's still not present in my perl v5.8.7 built for i486-linux:

    sidhekin@blackbox:~$ perl foreach my $thing (qw/foo bar baz/) { print "$thing -> "; my $c = chop ${\$thing}; print " $thing,$c\n"; } __END__ Modification of a read-only value attempted at - line 3. foo ->

    print "Just another Perl ${\(trickster and hacker)},"
    The Sidhekin proves Sidhe did it!

Re^2: foreach funny business
by krunchky (Sexton) on Jun 29, 2006 at 22:01 UTC
    On a debian stable machine I have, I see that that code (${\$thing}) on v5.8.4 built for i386-linux-thread-multi does not die, produces the usual
    foo -> foo,o bar -> bar,r baz -> baz,z
    So, um, there's another data point.