For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > July 2004 > Priority









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Priority
Vito Corleone

2004-07-23, 3:56 am

Hi,

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

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

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

Thank you.
Vito
Sam Holden

2004-07-23, 3:56 am

On Fri, 23 Jul 2004 11:08:10 +0900,
Vito Corleone <corleone@godfather.com> wrote:
> 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. Romano

2004-07-23, 3:56 am

Vito Corleone <corleone@godfather.com> wrote in message news:<20040723110810.7311a9d6.corleone@godfather.com>...
>
> 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
Michele Dondi

2004-07-28, 9:00 pm

On Fri, 23 Jul 2004 11:08:10 +0900, Vito Corleone
<corleone@godfather.com> wrote:

>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
--
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
"perl bug File::Basename and Perl's nature"
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com