On Tue, Jul 10, 2001 at 11:01:51PM +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;

You don't need switch to replace this code:

    $y = $x; # poof!

However, Perl has various ways of doing things like switch, see perldoc -q
switch or
http://www.perldoc.com/perl5.6/pod/perlfaq7.html#How%20do%20I%20create%20a%20switch%20or%20case%20statement%3f.

This was discussed recently in another thread.



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

'if $y' and '$y > 0' are testing for slightly different things.  The
equivalent would be '$y and y()'.

I've always taken perlstyle's advice to keep the important part up front.
The condition here is not as important as the action taken.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

Reply via email to