|
|
Sort files into date-labeled subfolders using Perl
Hmm, for what it's worth, the stat function in the script needlessly performs a second stat(2) system call; the previous "-f" has just done a stat and left the results conveniently sitting around, all error-checked and safe and ready for our use, via the special "_" filehandle. Quoting perlfunc(1): If any of the file tests (or either the "stat" or "lstat" operators) are given the special filehandle consisting of a solitary underline, then the stat structure of the previous file test (or stat operator) is used, saving a system call. Thus: my $mtime = (stat $name)[9] or next; can become: my $mtime = (stat _)[9]; And despite what the article says, the script does have error checking on all the file IO, so it looks decently safe to me. It will, of course, cheerfully mass-change whatever directory you tell it to, but then... you told it to, and Unix assumes you know what you're doing.
Sort files into date-labeled subfolders using Perl
I avoided the bizarre "_" mostly because it isn't really saving that much time on this one-off script. It's also one of the few things I invented for Perl, so I can avoid it when I want. :) |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.07 seconds |
|