Paul <[EMAIL PROTECTED]> wrote:
>When it matters is when the visual appearance of your script is notably
>altered. Sometimes the postfix is neater -- personally, I don't like
>opening and closing a block on the same line in an if, but that's just
>me... and I *do* do it when I have a conditional else, and both are
>just one line.
>
>   if ($x) { y() } else { z() }
>
>though usually they're long enough that I drop them to seperate lines.
>
>   if    ($x) { x() }
>   elsif ($y) { y() }
>   else       { z() }
>
>I don't like that structure, either, and often rewrite it with a
>trinary:
>
>   $x ? x() :
>   $y ? y() :
>   $z ? z() ;
>
>But what counts most (aside from making it do what you want) is that
>you can read it, that you can read it and edit it without a headache in
>six months or a year, and that the next guy can read it and edit it
>without having to come beat you up. =o)

lol, yes, you always have to make compromise between readable and
all-in-one-line code.

Btw, when we talk about structures is there something like switch in perl
which could replace following code?

$x==1 and $y = 1;
$x==2 and $y = 2;
$x==3 and $y = 3;

>I like postfix conditions whenever I can use them, but I like them best
>when I have a complex condition that has optional parts:
>
>   if ($x) {
>      x();       # doesn't execute unless $x
>      y() if $y; # doesn't execute unless $x *AND* $y
>   }
>
>y() is ideal for a postfix, because all other conditions have already
>been tested; this keeps the program from suffering excessive
>indentation caused by another block of curlies, though with such a

Yes, although I like conditions on the first place thus,
y() if $y;
could be replaced by:
$y >0 and y();

>So, to answer your question, it depends largely on the code your
>writing, but mostly on someone's style.

tnx.



-- 
Matija

Reply via email to