At 11:01 PM 7/10/01 +0200, Matija Papec wrote:
>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;
There are at least 22 ways of doing it (according to a Tom Christiansen
FMTYEWTK). How about
$y = $x if $x >= 1 && $x <= 3;
Leaving off the condition alters the semantics, contrary to a previous
answer. Or
$y = $x == 1 ? 1
: $x == 2 ? 2
: $x == 3 ? 3
: $y;
Granted, it rankles somewhat to repeat $x in there, but the only
parameterized alternatives I can come up with are too hideous to show here.
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com