You could still do something like
return undef unless defined $name = askFor(title => 'Name:');
# do stuff with $name
return undef unless defined $cigs = askFor(title => 'Cigarettes:');
# do stuff with $cigs
# ...
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:
sub askFor {
# ...
die if $pressed_cancel;
# ...
}
# ...
eval {
$name = askFor(title => 'Name:');
# do stuff with $name
$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 {
# ...
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. |