The stupid question is the question not asked | |
PerlMonks |
(dkubb) Re: (3) removing x from a listby dkubb (Deacon) |
on Apr 20, 2001 at 09:03 UTC ( [id://74088]=note: print w/replies, xml ) | Need Help?? |
Sometimes it's easier just to say what you will allow, and exclude everything else, than to exclude a multitude of patterns. You're likely to miss something in the process. This statement holds true in everything from security, user input validation, and to your specific problem. Since you are making a list of mp3 files, you could only allow files with the extension .mp3 to get into your @songs array, and exclude all others. Also, it's usually a good idea to sort after you have removed as much as possible from your list. Why bother to sort something that could have less elements in the near future? =) The original sample code you posted reads the directory, copies the file names into an array, then sorts the array and copies it back again to the same array. Of course, if efficiency was really important, I wouldn't have used grep or a regex, but I think this illustrates the point:
In Section
Seekers of Perl Wisdom
|
|