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

Re^3: resetting a foreach loop!

by brostad (Monk)
on Nov 17, 2017 at 11:27 UTC ( #1203655=note: print w/replies, xml ) Need Help??


in reply to Re^2: resetting a foreach loop!
in thread resetting a foreach loop!

Sorting the same array twice and assigning the results to two new arrays, potentially very long, is a bit wasteful when all you want is to find the smallest and largest value in the array. You could for instance do something like this:

 my($largest, $smallest) = (sort { $b <=> $a } @array)[0,-1];

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2021-04-11 05:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?