[Memphis.pm] sorts

Keith W. Sheffield sheff at pobox.com
Thu Oct 5 23:05:35 CDT 2000


I though of ways to compact the sort demos given tonight and I got the
following scripts at the end of this post.

Two questions

1. Is the reason why <=> doesn't work with listing #2 due to byte ordering
or because perl assumes the output of pack is always a string and won't do
integer compares?

2. I've tried using print ( map ..... <>), "\n"; and the last newline never
gets printed.  Why is that?


(listing 1 is faster, BTW).

---- listing 1 ----
#!/usr/bin/perl
{
local $,="\n";
print map {$_->[0]} sort {$a->[1] <=> $b->[1]} map {chomp; [ $_,  
	join('', map { sprintf "%03d", $_;} split(/\./)) ]; } <>;
print "\n";
}
-----
----- listing 2 ---
#!/usr/bin/perl
{
local $,="\n";
print map {$_->[0]} sort {$a->[1] cmp $b->[1]} map {chomp; [ $_, 
	pack("C4", split(/\./)) ]; } <>;
print "\n";
}
------


-- 
-------------------- Keith W. Sheffield  sheff at pobox.com -------------------- 
NOW. Let my people go, land of goshen.
GO. I will be with thee, bush of fire.                       -- RTL:CD v2 1-4
-------------- [lyrics copyright, Creeping Death Music, ASCAP] -------------- 

----------------------------------------------------------------------------
To unsubscribe, please send email to majordomo at pm.org
with 'unsubscribe memphis-pm-list' in the body of the message.
----------------------------------------------------------------------------




More information about the Memphis-pm mailing list