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


In reply to Re: foreach funny business by Hue-Bond
in thread foreach funny business by krunchky

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.