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" }