Hi all, i was working on a function to sort ip like strings, and ran into a couple of odd things. Well, here is the sort function - it could be done differently i know, but it shows my situation:
use strict;
...
sub ip_sorter {
my $a_parts = split /\./, $a;
my $b_parts = split /\./, $b;
my @a_parts = split /\./, $a;
my @b_parts = split /\./, $b;
my $result;
map { return $result if $result = ($a_parts[$_] <=> $b_parts[$_])
+} (0 .. $#a_parts);
so, 1 issue i had was that i couldnt put "no strict" in the map block. I dont know why this is, any insight would be great.
Also, i was unable to find any variable that perl implicitly sets as the result of a comparison. Im thinking something analogous to $! - the value of C errno. So lets just pretend that $^C gets set to the result of the last comparison operation. then i could rewrite my sort with this line:
...
map { return $^C if ($a_parts[$_] <=> $b_parts[$_]) };
...
I've looked for this variable at
search.cpan.org/author/JHI/perl-5.8.0/pod/perlvar.pod to no avail.
Fixed typo at author's req - dvergin 2003-05-14