How can I sort an array so that certain file extensions sort to the top?

Posted by rarbox on Stack Overflow See other posts from Stack Overflow or by rarbox
Published on 2010-03-26T17:36:30Z Indexed on 2010/03/26 18:33 UTC
Read the original article Hit count: 240

Filed under:
|

I have an array containing a list of files. I want to sort it in a way that it will let me have .txt files in the beginning of the array and the rest of files after that.

This is what I'm doing now, which works fine.

@files = (grep(/\.txt$/,@files),grep(!/\.txt$/,@files));

Is there a better way to do it though?

© Stack Overflow or respective owner

Related posts about perl

Related posts about array