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

Boolean logic is your friend.
return undef unless defined($name = askFor(title => 'Name:')) and defined($cigs = askFor(title => 'Cigarettes:'));
That return undef should probably be a plain return, unless Tk is as fastidious about return values as GtkPerl.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re^2: Double your return!!!!
by schweini (Friar) on Feb 19, 2003 at 08:32 UTC
    okay, i don't consider my self very 'leet, but - just to defend my honor (my parents could read this someday! :-), i DO know and.
    that one doesn't really help a lot, because then my whole script would consist of a gigantic concatenation of and clauses.
    besides - mea maxima culpa - i actually do stuff in between my user interaction things, so that one wouldn't work (should've showed that, though)

    thanks for the tip, though!

    by the way: what is the voting etiquette for situations like this? if i were an even bloodier newbie than i am, this one would have helped, and it's really nice of you to help me this way - OTOH, it didn't really help ME, and is a rather...ermm..."banal" thing (really no offense!).
    i'll ++ it, but i was just wondering how "valuable" votes are....

    kali nixta kai evxaristo
    (pardon the horrific ASCII-sation :-)
      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.

        i really liked the last approach - thanks.