in reply to Regex Or Die!

Flip it around.

if ( /^(foo|bar)/ ) { my $useful_code; } else { die "What the heck?!\n"; }

Replies are listed 'Best First'.
Re^2: Regex Or Die!
by djp (Hermit) on Oct 02, 2006 at 05:24 UTC
    I downvoted this, it's a common but poor way of programming. You should deal with the errors up front, as close as possible to the test, then let your 'normal' case proceed:
    if ( ! /^(foo|bar)/ ) { die "What the heck?!\n"; } my $useful_code; ...