Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

gabor (1626)

gabor
  (email not shown publicly)
http://szabgab.com/

Perl developer and trainer [szabgab.com]
Test automation using Perl [szabgab.com]

Journal of gabor (1626)

Tuesday July 29, 2003
10:31 AM

I am surprised by sort

[ #13757 ]
@a=qw(abc def ghi);
@b = map {chop $_} sort @a;
print "@a";

prints the following
# ab de gh

I though the sort already returns copy of the original values so the chop would affect only these copies and thus only @b. In @a I was expecting
# abc def ghi

 

This also means that the following code:
@b = map {chop $_} sort qw(ab cd ef);
print "OK\n"

sais:
Modification of a read-only value attempted at -e line 1.

instead of OK

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Read the description of grep carefully, and note what it says about aliasing. (Yeah, I know you're using map, and the POD for map doesn't say anything about aliasing (at least not in 5.8), but map and grep behave behave the same in this regard.)
    • Uh, never mind. The issue really is with sort, and the lack of info in perlfunc on sort's aliasing behavior.