perlquestion
shemp
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:
<CODE>
use strict;
...
sub ip_sorter {</code><tt>
<strike>my $a_parts = split /\./, $a;</strike><br />
<strike>my $b_parts = split /\./, $b;</strike></tt>
<code> my @a_parts = split /\./, $a;
my @b_parts = split /\./, $b;
my $result;
map { return $result if $result = ($a_parts[$_] <=> $b_parts[$_]) } (0 .. $#a_parts);
</CODE>
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.
<BR>
<BR>
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:
<CODE>
...
map { return $^C if ($a_parts[$_] <=> $b_parts[$_]) };
...
</CODE>
I've looked for this variable at <A HREF="http://search.cpan.org/author/JHI/perl-5.8.0/pod/perlvar.pod">search.cpan.org/author/JHI/perl-5.8.0/pod/perlvar.pod</A> to no avail.
<p><font size="-2">Fixed typo at author's req - [dvergin] 2003-05-14</font></p>