Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^2: stat : error handling

by gepebril69 (Scribe)
on Jan 03, 2013 at 14:08 UTC ( #1011455=note: print w/ replies, xml ) Need Help??

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

Thx Johngg

I stick to the non-die solutions. They are not real handy in 24/7 operational systems.... ;)

Comment on Re^2: stat : error handling
Replies are listed 'Best First'.
Re^3: stat : error handling
by Athanasius (Canon) on Jan 03, 2013 at 14:20 UTC

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

    #! perl use Modern::Perl; for my $file ('', '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 File '' 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,

Re^3: stat : error handling
by johngg (Abbot) on Jan 03, 2013 at 16:05 UTC

    The solution was $! and, as Athanasius points out, die had nothing to do with it other than to illustrate that the variable is available ;-)



Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2015-11-26 21:21 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (707 votes), past polls