Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Tips for elegance

by japhy (Canon)
on Jun 06, 2006 at 12:08 UTC ( [id://553797]=note: print w/replies, xml ) Need Help??


in reply to Tips for elegance

Is no one paying attention to the fact that the OP is using `ls -lto ...` to get the modification time of the files? I strongly suggest you use stat() or the -M filetest for this instead. It's much cleaner, faster, and system-independent, and there's no hairy regex necessary for parsing out the date. And by the way, my `ls -lto ...` doesn't zero-pad the day, so your regex would fail on my system.
my @months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); my @dates; for my $f (@files) { my $mod_time = (stat $f)[9]; my ($min, $hour, $day, $mon) = (localtime $mod_time)[1..4]; print "$f modified on $months[$mon] $day, $hour:$min\n"; # or if you want zero-padding... printf "%s modified on %3s %02d, %02d:%02d\n", $f, $months[$mon], $d +ay, $hour, $min; }
Please see stat for more details.

Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://553797]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-24 05:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found