Both methods are practically the same in terms of speed. When you do foreach (sort @a), the foreach doesn't loop over @a but instead over the anonymous (and temporary) array that was returned from the sort function.
The only difference of the two methods is that the first method stores the (anonymous) sorted array into @a before going into the foreach loop, while the second method leaves the sorted array anonymous.
In reply to Re: How foreach loops decide what to iterate through
by jethro
in thread How foreach loops decide what to iterate through
by lefthanded
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |