in reply to Re: Re^2: Double your return!!!!
in thread Double your return!!!!

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.

Replies are listed 'Best First'.
Re: Re^4: Double your return!!!!
by schweini (Friar) on Feb 20, 2003 at 16:55 UTC
    i really liked the last approach - thanks.