Priority

V

Vito Corleone

Hi,

If I write:
return $x || undef();

Which will be executed first? Is it:
(return $x) || undef();

or
return ($x || undef());

Thank you.
Vito
 
S

Sam Holden

Hi,

If I write:
return $x || undef();

Which will be executed first? Is it:
(return $x) || undef();

or
return ($x || undef());

The later.

The former can be achieved by using the lower precedence 'or':

return $x or undef();

But that's useless (I don't think there is a situation in which
return can fail - and in which the code compiles).
 
J

J. Romano

Vito Corleone said:
If I write:
return $x || undef();
Which will be executed first? Is it:
(return $x) || undef();
or
return ($x || undef());


Dear Vito,

Sometimes it's not immediately clear how Perl will parse an
expression. In cases like these, I use the "-MO=Deparse,-p" switch,
like this:

# In UNIX:
perl -MO=Deparse,-p -e 'sub { return $x || undef(); }'

# In DOS:
perl -MO=Deparse,-p -e "sub { return $x || undef(); }"

(I put your expression inside a subroutine in order to make the
one-liner compile.)

The output of this command shows the line:

return(($x || undef()));

signifying that your second guess is correct.

Hope this helps,

-- Jean-Luc
 
M

Michele Dondi

Hi,

If I write:
return $x || undef();

Which will be executed first? Is it:
(return $x) || undef();

or
return ($x || undef());

perldoc perlop

and/or, as another poster already suggested,

perl -MO=Deparse,-p


HTH,
Michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,416
Latest member
LionelQ387

Latest Threads

Top