You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by BeerBong <al...@samara.net> on 2000/02/24 17:18:42 UTC

Perl question...

Hello!

Sorry for clean Perl question, although I use Apache::ASP. mod_perl is only
one my perl related mail list.

Simple example
---------------------
my $test1 = undef;
my $test2 = 2;
my $test3 = $test1 or $test2;
print "Value - $test3";
---------------------
returns
---------------------
Value -
---------------------
when
---------------------
my $test1 = undef;
my $test2 = 2;
my $test3 = $test1 || $test2;
print "Value - $test3";
---------------------
returns
---------------------
Value - 2
---------------------

We can read "Programming Perl" Chapter 2.5

2.5.20 Logical and, or, not, and xor

As more readable alternatives to &&, ||, and !, Perl provides the and, or
and not operators. The behavior of these operators _IS IDENTICAL_ - in
particular, they short-circuit the same way.

Why?
Where I can read more about it, if it is not a bug ?

PS. I can't imagine that it is a bug!
------------------------------------
Sergey Polyakov - Chief of WebZavod.
http://www.webzavod.ru


Re: [OT] Perl question...

Posted by "Randal L. Schwartz" <me...@stonehenge.com>.
>>>>> "DeWitt" == DeWitt Clinton <de...@eziba.com> writes:

DeWitt> Right.  And those operators were not created as a more readable
DeWitt> alternative.  They were created *because* their precedence is
DeWitt> different.

Well, the "xor" operator didn't have a trivial punctuation equivalent,
so there's actually added functionality.  Yeah, you can do something like:

        !(EXPRESSION_A) != !(EXPRESSION_B)

But that's just messy, when you can do this instead:

        EXPRESSION_A xor EXPRESSION_B

DeWitt> Of course, this is just silly, and you should use parentheses!

If you want to use LISP, you know where to find it. :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<me...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Re: [OT] Perl question...

Posted by DeWitt Clinton <de...@eziba.com>.
On Thu, Feb 24, 2000 at 05:31:57PM +0100, Victor Zamouline wrote:
> > As more readable alternatives to &&, ||, and !, Perl provides the and, or
> > and not operators. The behavior of these operators _IS IDENTICAL_ - in
> > particular, they short-circuit the same way.
> 
> I guess their _behavior_ is identical but their _precedence_ is not the
> same.

Right.  And those operators were not created as a more readable
alternative.  They were created *because* their precedence is
different.  The "and," "or," and "not" operators are supposed to be
lower in precendence so that you can say things like:

  my $foo = $bar || $default or
     die("Couldn't set foo");

Of course, this is just silly, and you should use parentheses!

-DeWitt

On-topic reply to [OT] question...

Posted by "G.W. Haywood" <ge...@jubileegroup.co.uk>.
Hi there,

On Thu, 24 Feb 2000, Rodney Broom (OE) wrote:

> "OT", I haven't heard this. On the topic of being off-topic, is there a
> standard parlance that folks use in this list? FAQs to read? Standard
> mod_perl docs that folks usually forget to check first?
> 
> I could used the first question answered, but I think that alot of the rest
> of us could use the latter as well.

/usr/local/mod_perl/SUPPORT

73,
Ged.



Re: [OT] Re: Perl question...

Posted by "Rodney Broom (OE)" <rb...@home.com>.
----- Original Message -----
From: "Stas Bekman" <sb...@iname.com>
> Just please attach the [OT] tag for off-topic questions, even if the
> original poster has ignored the advice. I beleive that with a little
> effort of all of us educating ourselves and users we will have the best
> mailing list ever :)

"OT", I haven't heard this. On the topic of being off-topic, is there a
standard parlance that folks use in this list? FAQs to read? Standard
mod_perl docs that folks usually forget to check first?

I could used the first question answered, but I think that alot of the rest
of us could use the latter as well.

Rodney


[OT] Re: Perl question...

Posted by Stas Bekman <sb...@iname.com>.
On Thu, 24 Feb 2000, Victor Zamouline wrote:

> > As more readable alternatives to &&, ||, and !, Perl provides the and, or
> > and not operators. The behavior of these operators _IS IDENTICAL_ - in
> > particular, they short-circuit the same way.
> 
> I guess their _behavior_ is identical but their _precedence_ is not the
> same.

That's correct!

Just please attach the [OT] tag for off-topic questions, even if the
original poster has ignored the advice. I beleive that with a little
effort of all of us educating ourselves and users we will have the best
mailing list ever :)

  
> I think that
> 
> my $test3 = $test1 or $test2
> 
> is interpreted as
> 
> (my $test3 = $test1) or $test2
> 
> so you should try
> 
> my $test3 = ($test1 or $test2)
> 
> Victor.
> 
> 



_______________________________________________________________________
Stas Bekman    mailto:sbekman@iname.com      http://www.stason.org/stas
Perl,CGI,Apache,Linux,Web,Java,PC     http://www.stason.org/stas/TULARC
perl.apache.org    modperl.sourcegarden.org   perlmonth.com    perl.org
single o-> + single o-+ = singlesheaven    http://www.singlesheaven.com


Re: Perl question...

Posted by Victor Zamouline <vi...@jazzvalley.com>.
> As more readable alternatives to &&, ||, and !, Perl provides the and, or
> and not operators. The behavior of these operators _IS IDENTICAL_ - in
> particular, they short-circuit the same way.

I guess their _behavior_ is identical but their _precedence_ is not the
same.

I think that

my $test3 = $test1 or $test2

is interpreted as

(my $test3 = $test1) or $test2

so you should try

my $test3 = ($test1 or $test2)

Victor.