Spaceship Operator - I canna git it t' worrrk, cap'n!
by Quackamoe T-Bird-S <quackamoe(at)yahoo.com>
|
Date: |
Thu, 6 Apr 2000 13:40:01 -0700 (PDT) |
To: |
hwg-languages(at)hwg.org |
|
todo: View
Thread,
Original
|
|
Right here in front of me is _Learning Perl_. On
p. 170 is the following code to get an array of
numbers sorted numerically (1,2,3,11,111,21,30, etc
instead of 1,11,111,2,21,3,30, etc):
@rightlist = sort { $a <=> $b } @wronglist;
And right here on my Ultra monitor screen I have
the following code to do the same thing:
#!/apps/LWperl/bin/perl -w[1]
while (<>){ # reads the file of numbers
@wordlist = $_;
@sortwordlist = sort { $a <=> $b } @wordlist;
print @sortwordlist;
}
The file being read in is a list of numbers with
revision letters or a dash like so:
5335 -
5336 A
5337 B
5338 -
There's 2354 numbers. I just want them sorted in
numeric order. What am I doing wrong? Is it the
revision letters? I tried
@sortwordlist = sort { $a cmp $b } @wordlist;
Also no luck. Suggestions?
Terry Fowler
Boeing
[1] No matter how I try I can't get the SysAdmin to
install perl in /usr/bin/perl. Go figure.
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com
HWG: hwg-languages mailing list archives,
maintained by Webmasters @ IWA