SPUG: Weirdness in map

Aaron West tallpeak at hotmail.com
Wed Jan 25 13:24:08 PST 2006


After the last post, I was wondering if I had any .cf files in my coldfusion
directory....and wrote this one-liner. Any idea why these have different
output?

In the first, the reverse inside the map apparently doesn't work. It's as if
sprintf is looking at the original value of $_ before it was reversed,
somehow. So I appended "" to the value returned by reverse, in the second
version, and it worked!???

========================================
Version 1:

[user at machinename] /cygdrive/c/CFusionMX
$ find . -name "*.cf*" | \
	perl -nle '($_) = split("\\.", reverse($_), 2); 
	$extr{$_}++;
	END{print map {sprintf("%s\t%d\n", reverse($_), $extr{$_}) } 
	sort keys %extr}'
cfc     19
dlo     1
dltfc   1
gfc     1
mfc     959
~1~     1

========================================
Version 2:

[user at machinename] /cygdrive/c/CFusionMX
find . -name "*.cf*" | \
	perl -nle '($_) = split("\\.", reverse($_), 2); 
	$extr{$_}++;
	END{print map {sprintf("%s\t%d\n", reverse($_) . "", $extr{$_}) } 
	sort keys %extr}'
cfc     19
old     1
cftld   1
cfg     1
cfm     959
~1~     1

========================================

$ perl -v

This is perl, v5.8.7 built for cygwin-thread-multi-64int
(with 1 registered patch, see perl -V for more detail)
..


More information about the spug-list mailing list