in reply to Re: Regex Or Die!
in thread Regex Or Die!

die "whatever" unless /^(foo|bar)/;

I like that it's hard to miss a die with this method. It's the first word on the line, the die jumps out and screams "This condition is important!"

Which also means that this style can get distracting if you're doing a lot of sanity checks inline. So, that's a good reason to encapsulate your sanity checks in subroutines.

$user_number = &validate_user_number($input)

is cleaner than

die "Numbers only please." unless ($input =~ /[0-9]+/); $user_number = $input;

Plus, with a subroutine, you can add more checks without making the usage of that sub any harder to understand.