What happens if you return an array reference instead of an array at the end of this function? (Depending on how large $limit is, you might cause Perl to copy a lot of data.)
What happens if, instead of reading the whole file into an array and then sorting it, you keep track of the largest n lines you've seen and read the file line by line?
Improve your skills with Modern Perl: the free book.
In reply to Re: Optimizing I/O intensive subroutine
by chromatic
in thread Optimizing I/O intensive subroutine
by hperange
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |