That would at least reduce your two statements to a single one. If you really insist on a "double return" you need to do something like this:return undef unless defined $name = askFor(title => 'Name:'); # do stuff with $name return undef unless defined $cigs = askFor(title => 'Cigarettes:'); # do stuff with $cigs # ...
which, incidentally, is really the standard idiom for such cases (think DBI). Another option might be to change your askFor() so that it assigns the result itself and returns whether or not it succeeded:sub askFor { # ... die if $pressed_cancel; # ... } # ... eval { $name = askFor(title => 'Name:'); # do stuff with $name $cigs = askFor(title => 'Cigarettes:'); # do stuff with $cigs }
sub askFor { # ... return if $pressed_cancel; ${$arg{Var}} = $user_input; } # ... return unless askFor(title => 'Name:', Var => \$name); # do stuff with $name return unless askFor(title => 'Cigarettes:', Var => \$cigs); # do stuff with $cigs
Plenty of ways to do what you want, really.
Oh, and about the voting - don't sweat it. Who cares.
Makeshifts last the longest.
In reply to Re^4: Double your return!!!!
by Aristotle
in thread Double your return!!!!
by bsb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |