Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: Sorting files by 3 numbers in the name

by LanX (Archbishop)
on May 26, 2017 at 15:27 UTC ( #1191299=note: print w/replies, xml ) Need Help??


in reply to Re^3: Sorting files by 3 numbers in the name
in thread Sorting files by 3 numbers in the name

agreed, with split it's a plus! =)

I wonder about the best idiomatic way ( with or w/o List::Util ) to shorten the or chain such that we don't need to repeat the field names.

use strict; use warnings; use Data::Dump; use List::Util qw/first/; $\="\n"; # --- init my @fields = qw( RUN DISTRICT COPY TOTAL ); my %a = map { $_ => 1- int rand 3 } @fields; my %b = map { $_ => 1- int rand 3 } @fields; dd \@fields,\%a,\%b; # --- w/o List::Util my $last; my $field; for (@fields) { $field =$_; $last = $a{$_} <=> $b{$_} and last; } print "$field,$last"; # --- with List::Util print first { $last = $a{$_} <=> $b{$_} } @fields; print $last;

( ["RUN", "DISTRICT", "COPY", "TOTAL"], { COPY => -1, DISTRICT => 1, RUN => 1, TOTAL => -1 }, { COPY => -1, DISTRICT => 1, RUN => 1, TOTAL => 0 }, ) TOTAL,-1 TOTAL -1

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1191299]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2018-11-20 21:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (232 votes). Check out past polls.

    Notices?