in reply to How do I use a block as an ‘or’ clause instead of a simple die?

To process exceptions rather than automatically dying:

eval { # my code here # for example, a call to whatever subroutine is calling # $ftp->put($my_file) or die return 1; } or do { my $err=$@; # my exception handling code here, uses $err, not $@ }

And some explanatory notes:

Best, beth

Replies are listed 'Best First'.
Re^2: How do I use a block as an ‘or’ clause instead of a simple die?
by CountZero (Bishop) on Apr 18, 2009 at 18:32 UTC
    we have to make sure that the last line is always true. Returning 1 does that
    Your idiom would jump out of any subroutine you are in at the moment. Just 1; would be sufficient to have a value of 1 'returned' and avoid the or branch.

    Forget the above, it is wrong. As per the docs: return EXPR: Returns from a subroutine, eval, or do FILE with the value given in EXPR

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James