http://www.perlmonks.org?node_id=1033274


in reply to Re^4: Question regarding handling exceptions in subroutine
in thread Question regarding handling exceptions in subroutine

Thanks, you're right about the other issues, I was simply in a hurry to outline a way forwardat least that's the excuse I'm using :-)

Question: Why 'eval' this instead of just running this in backticks? I understand the command can fail, but in those cases it simply returns an error code.

If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)
  • Comment on Re^5: Question regarding handling exceptions in subroutine

Replies are listed 'Best First'.
Re^6: Question regarding handling exceptions in subroutine
by karlgoethebier (Abbot) on May 13, 2013 at 12:31 UTC
    "Why 'eval' this..."

    Good question. Because:

    1. I'm paranoid
    2. I didn't think
    3. I was in a hurry

    Perhaps all items match ;-)

    My posts aren't correct: it would only make (some) sense to eval if there is a die in the block that sets $@ (perhaps something wrong with $command, like a non-existing file etc). But this could be also trapped before with a file test operator...a.s.o

    I just wanted to say that you forgot to right shift, as you already noticed. That would have been enough. Sorry :-(

    Update:

    To tell the truth: from time to time i need to take a look again at Perl documentation about this issues. I think it can be tricky - depending on the situation. And even if it isn't really tricky, i get a little confused about it from time to time...

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»