Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^5: A set of new operators. In keeping with the design of Perl? (aliasing)

by Aristotle (Chancellor)
on May 21, 2003 at 20:58 UTC ( #259887=note: print w/ replies, xml ) Need Help??


in reply to Re: Re^3: A set of new operators. In keeping with the design of Perl? (aliasing)
in thread A set of new operators. In keeping with the design of Perl?

As for the single-pass problem, you can do that too:

use List::Util qw(reduce); @hash{$set}{qw(min max)} = @{ reduce { return [ $a, $b ] if 'ARRAY' ne ref $a; return $a->[0] < $b ? [ $b, $a->[1] ] : $a->[1] > $b ? [ $a->[0], $b ] : $a; } @{$hash{$set}{data}} };
Admittedly more hoop jumping here. Of course that doesn't address the memory problem, but in that case I'd still opt for a counter in a while loop instead. (In keeping with the corresponding use of while and each to traverse a hash.)
for my $min ($hash{$set}{min}) { my $data = $hash{$set}{data}; my $i = -1; while(++$i < @$data) { $min = $min < $data->{$i} ? $min : $data->{$i}; } }

Makeshifts last the longest.


Comment on Re^5: A set of new operators. In keeping with the design of Perl? (aliasing)
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2015-07-01 21:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (22 votes), past polls