in reply to pop sort strangeness
pop pulls one item off the array. sort returns a list. That list may be assigned to an array, or it may be kept as a list. You're keeping it as a list, in a sort of scratch storage. In that form, it's not popable. ;)
This will work:
my $max = pop @{[ sort @vals ]};
This works because you're turning the list returned by sort into an anonymous array, which is immediately dereferenced.
Either way, this is an inefficient solution, as it requires that the entire list be sorted each time you take a max. Use the List::Util max() function, or if you're going to roll your own, just do a linear search.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: pop sort strangeness
by Brovnik (Hermit) on Nov 15, 2004 at 16:18 UTC | |
by davido (Cardinal) on Nov 15, 2004 at 16:27 UTC | |
by sleepingsquirrel (Chaplain) on Nov 17, 2004 at 19:43 UTC | |
by Eimi Metamorphoumai (Deacon) on Nov 17, 2004 at 20:06 UTC |