chaining defines
  Home FAQ Contact Sign in
perl.beginners only
 
Advanced search
POPULAR GROUPS

more...

perl.beginners Profile…
 Up
chaining defines         


Author: Robert Hicks
Date: May 6, 2008 06:49

Is there anything wrong with:

if ( defined $one && defined $two && $one eq $two ) {
#### do something
}
4 Comments
Re: chaining defines         


Author: Yitzle
Date: May 6, 2008 07:43

On Tue, May 6, 2008 at 9:49 AM, Robert Hicks gmail.com> wrote:
> Is there anything wrong with:
>
> if ( defined $one && defined $two && $one eq $two ) {
> #### do something
> }

No. Its fine.
You might be interested in "Operator Precedence and Associativity" [1]

[1] http://perldoc.perl.org/perlop.html#Operator-Precedence-and-Associativity
no comments
Re: chaining defines         


Author: Jenda Krynicky
Date: May 6, 2008 09:04

From: Robert Hicks gmail.com>
> Is there anything wrong with:
>
> if ( defined $one && defined $two && $one eq $two ) {
> #### do something
> }

As far as I can tell not. I was afraid the operator precedence might
play tricks with it, but looks like it doesn't:

V:\>perl -MO=Deparse -e "defined $one && defined $two && $one eq
$two"
$one eq $two if defined $one and defined $two;
-e syntax OK

V:\>perl -MO=Deparse -e "if(defined $one && defined $two && $one eq
$two) {print 'aha'}"
if (defined $one and defined $two and $one eq $two) {
print 'aha';
}
-e syntax OK

I would write it as
Show full article (1.01Kb)
no comments
Re: chaining defines         


Author: Robert Hicks
Date: May 6, 2008 09:27

Jenda Krynicky wrote:
> From: Robert Hicks gmail.com>
>> Is there anything wrong with:
>>
>> if ( defined $one && defined $two && $one eq $two ) {
>> #### do something
>> }
>
> As far as I can tell not. I was afraid the operator precedence might
> play tricks with it, but looks like it doesn't:
>
> V:\>perl -MO=Deparse -e "defined $one && defined $two && $one eq
> $two"
> $one eq $two if defined $one and defined $two;
> -e syntax OK
>
> V:\>perl -MO=Deparse -e "if(defined $one && defined $two && $one eq
> $two) {print 'aha'}"
> if (defined $one and defined $two and $one eq $two) {
> print 'aha'; ...
Show full article (0.95Kb)
no comments
Re: chaining defines         


Author: Peter Scott
Date: May 7, 2008 04:38

On Tue, 06 May 2008 18:04:00 +0200, Jenda Krynicky wrote:
> From: Robert Hicks gmail.com>
>> Is there anything wrong with:
>>
>> if ( defined $one && defined $two && $one eq $two ) {
>> #### do something
>> }
>
> As far as I can tell not. I was afraid the operator precedence might
> play tricks with it, but looks like it doesn't:
>
> V:\>perl -MO=Deparse -e "defined $one && defined $two && $one eq
> $two"
> $one eq $two if defined $one and defined $two;
> -e syntax OK

A bit more explicitly (and interestingly different):

$ perl -MO=Deparse,-p -e 'defined $one && defined $two && $one eq $two'
((defined($one) and defined($two)) and ($one eq $two));
-e syntax OK
Show full article (0.77Kb)
no comments