Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Continue block entry

by Gilimanjaro (Hermit)
on May 10, 2005 at 09:36 UTC ( #455481=note: print w/replies, xml ) Need Help??

in reply to Continue block entry

Sound like you may want to use eval for this, and die instead of next:

foreach (@a) { eval { die 'reason1' if check_condition1(); do_some_stuff(); die 'reason2' if check_condition2(); do_more_stuff(); die 'reason3' if check_condition3(); play_solitaire(); do_something_if_all_ok(); }; # a *real* error, if it doesn't start with 'reason' die if $@ && $@ !~ /^reason/; # save reason; you never know what other evals happen my $reason = $@; # usual continue code here do_something_always(); if($reason) { only_if_reason1() if $@ eq 'reason1' } }

You may want to die with an object of some kind, to easily distinguish between 'real' error, and your type of conditions.

Update: corrected the die regex to Do The Right Thang

Replies are listed 'Best First'.
Re^2: Continue block entry
by prowler (Friar) on May 12, 2005 at 00:02 UTC

    Thanks for the suggestion, but I assume you mean:

    die if $@ && $@ !~ /^reason/

    rather than '=~'.

     - Spelling is a demanding task that requies you full attention.

      yup. sorry. will update now...

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2022-08-18 02:05 GMT
Find Nodes?
    Voting Booth?

    No recent polls found