Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: stat : error handling

by Athanasius (Abbot)
on Jan 03, 2013 at 14:20 UTC ( #1011456=note: print w/ replies, xml ) Need Help??


in reply to Re^2: stat : error handling
in thread stat : error handling

Well, you don’t need to use die to get information from $!:

#! perl use Modern::Perl; for my $file ('465_SoPW.pl', 'Non-Existent.txt') { if (my @stats = stat $file) { say "File '$file' last modified: ", $stats[9]; } else { say "stat failed for file '$file': $!"; } }

Output (on my machine):

0:17 >perl 466_SoPW.pl File '465_SoPW.pl' last modified: 1357188675 stat failed for file 'Non-Existent.txt': No such file or directory 0:17 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


Comment on Re^3: stat : error handling
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2015-07-01 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (23 votes), past polls