in reply to foreach funny business
I just took the time to do some testing on several machines. All these accepted to modify the value:
$ perl -le'sub mychop(\$) { chop ${shift()} } print mychop $_ foreach +(qw/foo/);' o $ perl -le'sub mychop(\$) { chop ${$_[0]} } print mychop $_ foreach (q +w/foo/);' o This is perl, version 5.005_02 built for PA-RISC1.1 - HP-UX td192 B.11 +.11 This is perl, v5.8.3 built for i586-linux-thread-multi - SUSE LINUX En +terprise Server 9 This is perl, v5.8.3 built for IA64.ARCHREV_0-thread-multi - HP-UX td1 +64 B.11.23 This is perl, v5.8.3 built for x86_64-linux-thread-multi - SUSE LINUX +Enterprise Server 9 This is perl, v5.8.4 built for alpha-linux-thread-multi - Debian/Linux + 3.1 This is perl, v5.8.4 built for i386-linux-thread-multi - Debian/Linux +3.1 This is perl, v5.8.5 built for i386-linux-thread-multi - Red Hat Enter +prise Linux AS release 4 This is perl, v5.8.5 built for x86_64-linux-thread-multi - Red Hat Ent +erprise Linux AS release 4 This is perl, v5.8.8 built for hppa-linux-gnu-thread-multi - Debian/Li +nux 3.1
While these refused to:
> perl -le'sub mychop(\$) { chop ${shift()} } print mychop $_ foreach +(qw/foo/);' Modification of a read-only value attempted at -e line 1. > perl -le'sub mychop(\$) { chop ${$_[0]} } print mychop $_ foreach (q +w/foo/);' Modification of a read-only value attempted at -e line 1. This is perl, v5.8.0 built for alpha-dec_osf - Compaq Tru64 UNIX V5.1B This is perl, v5.8.0 built for i386-netbsd - NetBSD 3.0 This is perl, v5.8.6 built for alpha-freebsd - FreeBSD 6.0-RELEASE This is perl, v5.8.6 built for i386-freebsd-64int - FreeBSD 5.4-RELEAS +E
Update: I added the operating system by hand, it's not part of the perl -v output on any system.
--
David Serrano
|
|---|