--- Peter Cornelius <[EMAIL PROTECTED]> wrote:
> > Use:
> >   if (@ARGV and -T $ARGV[0]) { ... }
> 
> Just wondering if there is a reason for using the lower precedence
> 'and' here instead of '&&'?  I haven't been finding many uses for
> 'and' which tells me I might not fully understand it.

I've almost never written code that used && in perl.
'and' has a lower precedence, which is usually what you want with
boolean expressions. It lets you write the same syntax with less line
noise.

  if ($a = func() and $b) { # assigns $a from func(), then checks $b

does something different than

  if ($a = func() && $b) {  # assigns $a from (func() && $b) compare

Not that assignments in if's come highly recommended, but I have used
them....

Also, while a lot of C programmers tend to try doing things in the
familiar fashion, I believe 'and' is a lot more readable than '&&',
which is a plus, and it also helps you remember this is Perl, not C.
The same mentality that hangs onto && will write

  for(my $i=0; $i<10; $i++) { print $i }

when it's much cleaner, clearer, and more efficient to write

  for my $i (0..9) { print $i }

and to my mind, even better to say

  print for 0..9;

Why the different structures?
Because everyone does it differently.
Perl doesn't make you abandon one for another, but each has its
advantages....



__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/

Reply via email to