drclaw
Recent Actions
-
Posted Get more from you constants with constant::more to drclaw
One of my 'nuts and bolts' modules is constant::more. It declares constants, just like constant , however also gives you the ability to set these values in a consistent way from the command line…
-
Posted Faster and up to date HTTP Cookie Jar to drclaw
Hot off the keyboard, is HTTP::State in trial form anyway. This is HTTP cookie jar supporting public suffix, same site, cookie partitioning and other goodies from RFC6265bis-draft and CHIPS. It makes cookie handling on the client side more in…
-
Commented on The ordering operators
Neat. I do like a nice logical op chain....
Comment Threads
-
E. Choroba commented on
The ordering operators
I also use it sometimes when there are three different actions based on a comparison, turning something like
for my $x (1, 2, 3) { for my $y (1, 2, 3) { print "$x $y "; if ($x == $y) { print 'same'; } elsif ($x < $y) { print 'less'; } else { print 'greater'; } print "\n"; } }
into
for my $x (1, 2, 3) { for my $y (1, 2, 3) { print "$x $y ", qw( same greater less )[$x <=> $y], "\n"; } }
-
Aristotle commented on
The ordering operators
Mpapec:
Unfortunately the code has no control over the format of
$version
because that value comes from an API. So using a single comparison with padded numbers would require extra logic to munge both values to pad them first. And I can’t think of any even remotely concise and simple way of doing that robustly.Can you?
The best I can come up with is along the lines of
my @curr_ver = split /[.]/, $version; my @len = map length, @curr_ver; my ( $curr_padded, $min_padded ) = map…
-
Aristotle commented on
The ordering operators
Question is why at that point you wouldn’t just write this:
sub vcmp0 { my ($v1, $v2) = @_; my @v1 = split /[.]/, $v1; my @v2 = split /[.]/, $v2; $v1[0] <=> $v2[0] || $v1[1] <=> $v2[1] || $v1[2] <=> $v2[2]; }
Sure it’s a bit copy-pasty but IMO that’s a benefit rather than a drawback in this case.
About blogs.perl.org
blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.