Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Perl exception - multiple statement

by spazm (Monk)
on Jul 20, 2009 at 16:32 UTC ( [id://781683]=note: print w/replies, xml ) Need Help??


in reply to Perl exception - multiple statement

  1. when using eval, you want to check the status of $@ ( and not $? as you have in your snippet )
  2. system calls don't throw errors that you can check with eval.
  3. system returns 0 on success.
  4. $? and $!, which one is which, I tend to have to check the docs.

    system

    We can define our own system call that will throw an error (die) on failure.

    Quick example:

    sub my_system { system($_[0]) || die "$_[0] failed : $!"; } eval { my_system( "cp xyz.dat abc.dat" ); my_system("cp xyz.dat2 abc.dat2"); } if ($@) { print "Error occured : $@\n" }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-13 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found