On Wed, May 30, 2001 at 11:42:15AM -0700, Paul wrote:
> 
> --- 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.

Whereas I rarely use "and".

> '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.

> 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 '&&',

But I think && and || stand out better.

> 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 }

Hmmm.

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

.... and disadvantages.

I dabbled with "and" and "or" when they were added to the language, but
decided that in general I preferred && and ||, "if" and "unless".  Of
course the lower precedence operators have their place, but there is no
need to banish the higher precedence operators.

So, learn the precedence and use them as you see fit, or choose what
you're happy with and use parentheses as appropriate.

http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1999-05/msg01072.html

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

Reply via email to