TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [TCLUG:2586] perl question
Ben Luey wrote:
>
> In perl is there a good way to write a script such that
>
> if A and if B, then C
> if not A then C
> if A and not B then nothing?
>
> I'd like to write the script without typing C in twice. Also, if A, then I
> need to to some stuff to determine if B is true, so I can't do a combined
> if (A and B).
>
> Hope this makes sense,
I'd make B a subroutine that returns a boolean value. Since perl has
(optionally) short ciruited login it won't be called if a isn't true.
Something like this
if (!A || (A && (&B()))) { # that last ampersand means 'call
subroutine'
C
}
sub B {
stuff;
more stuff;
return (whatever == good);
}
--
Ry4an Brase - http://acm.cs.umn.edu/~ry4an - 612-623-9946
'If you're not a rebel when you're 20 you've got no heart; if
you're not establishment when you're 30 you've got no brain.'