[sf-perl] Odd behavior for dot operator?
david wright
david_v_wright at yahoo.com
Fri Mar 18 09:10:03 PDT 2011
A handy module for this sort of thing is B::Deparse.
>From the docs:
With -p, it uses parentheses (almost) whenever they would be legal.
This can be useful if you are used to LISP, or if you want to see how perl
parses your input.
[dwright~(8)]$ perl -w -MO=Deparse,-p
$x = 'a' . (defined $y)? $y :'undef' ."\n";
print $x;
^D
BEGIN { $^W = 1; }
($x = (('a' . defined($y)) ? $y : "undef\n"));
print($x);
- syntax OK
________________________________
From: Andrew Sigmund <ASIGMUND at altera.com>
To: Francisco Obispo <fobispo at isc.org>
Cc: "SanFrancisco-pm at pm.org" <SanFrancisco-pm at pm.org>
Sent: Thu, March 17, 2011 11:19:01 PM
Subject: Re: [sf-perl] Odd behavior for dot operator?
Yup, that was the problem. I verified that the precedence of the dot operator
is higher than that of the conditional operator.
So, by default, I was getting
$x = ( 'a' . (defined $y) )? $y .... which is always true, so perl was trying
to actually use the undefined $y, and thus gave me the warning.
Thanks Francisco.
Andy
-----Original Message-----
From: Francisco Obispo [mailto:fobispo at isc.org]
Sent: Thursday, March 17, 2011 23:03
To: Andrew Sigmund
Cc: SanFrancisco-pm at pm.org
Subject: Re: [sf-perl] Odd behavior for dot operator?
the problem is the precedence or the operators.
Try:
$x = 'a' . ( (defined $y) ? $y :'undef' ."\n"); # now I try to put something up
front
print $x;
On Mar 17, 2011, at 10:55 PM, Andrew Sigmund wrote:
> $x = 'a' . (defined $y)? $y :'undef' ."\n"; # now I try to put something up
>front
> print $x;
Francisco Obispo
Hosted@ Programme Manager
email: fobispo at isc.org
Phone: +1 650 423 1374 || INOC-DBA *3557* NOC
Key fingerprint = 532F 84EB 06B4 3806 D5FA 09C6 463E 614E B38D B1BE
Confidentiality Notice.
This message may contain information that is confidential or otherwise protected
from disclosure. If you are not the intended recipient, you are hereby notified
that any use, disclosure, dissemination, distribution, or copying of this
message, or any attachments, is strictly prohibited. If you have received this
message in error, please advise the sender by reply e-mail, and delete the
message and any attachments. Thank you.
_______________________________________________
SanFrancisco-pm mailing list
SanFrancisco-pm at pm.org
http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20110318/811b6ef1/attachment.html>
More information about the SanFrancisco-pm
mailing list