shemp has asked for the wisdom of the Perl Monks concerning the following question:
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:
my $a_parts = split /\./, $a;
my $b_parts = split /\./, $b;
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:
use strict; ... sub ip_sorter {
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.my @a_parts = split /\./, $a; my @b_parts = split /\./, $b; my $result; map { return $result if $result = ($a_parts[$_] <=> $b_parts[$_]) +} (0 .. $#a_parts);
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:
I've looked for this variable at search.cpan.org/author/JHI/perl-5.8.0/pod/perlvar.pod to no avail.... map { return $^C if ($a_parts[$_] <=> $b_parts[$_]) }; ...
Fixed typo at author's req - dvergin 2003-05-14
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Comparison result capture???
by pzbagel (Chaplain) on May 14, 2003 at 17:20 UTC | |
Re: Comparison result capture???
by chip (Curate) on May 14, 2003 at 16:22 UTC | |
by boo_radley (Parson) on May 14, 2003 at 17:10 UTC | |
by chip (Curate) on May 14, 2003 at 20:41 UTC | |
by dragonchild (Archbishop) on May 14, 2003 at 16:58 UTC | |
by chip (Curate) on May 14, 2003 at 20:44 UTC | |
by shemp (Deacon) on May 14, 2003 at 18:00 UTC | |
Re: Comparison result capture???
by flounder99 (Friar) on May 14, 2003 at 19:57 UTC |
Back to
Seekers of Perl Wisdom