addendum for perl and ls

today handgestrickt wrote about PHP, Perl and systemcalls. later we found a slightly faster Perl script:

here we mix perl with a systemcall to ls, telling it to list all subdirectories recursively and sort by modification time descending. in Perl we just chop the output into pieces.

test.pl

#/usr/bin/perl
$dir = '';
foreach(`ls -Rat1`) {
        if(/:$/) { $dir = substr($_,2,-2); }
        elsif(/\.(?:jpeg|jpg|jpe|gif|png)$/i) { print $dir.'/'.$_; }
}

this does the same task as todays Perl script. the result is now:

perl and ls took: 0.0277252197266 seconds

which is a little bit faster than yesterdays solution in Perl. additionally the code is shorter. unfortunately even this example is slower than the PHP solution.

Sunday, 03. June 2007 • trackback url

Add Comment

( to reply to a comment, click the reply link next to the comment )

Comment Title:
Your Name:
Email Address:
Make Public?
Website:
Make Public?

Comment:


Allowed XHTML tags : a, b, i, strong, code, acrynom, blockquote, abbr. Linebreaks will be converted automatically.


Captcha:

captcha image

Soundfile:


please type the content of the above image or the soundfile into the following form-field: