Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: resetting a foreach loop!

by brostad (Monk)
on Nov 17, 2017 at 11:27 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1203655]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-20 01:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found