<br><br><div class="gmail_quote">On Wed, Dec 3, 2008 at 6:50 PM, Jay Hannah <span dir="ltr"><<a href="mailto:jay@jays.net">jay@jays.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
From: <a href="mailto:brandonglesmann@gmail.com" target="_blank">brandonglesmann@gmail.com</a><br>
Date: December 3, 2008 4:42:30 PM CST<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Disclaimer: I have been out of perl programming for over two years. So, I am really rusty. Also I never used the perl debugger so I could be misinterpreting the output. Lastly, I am a coward which is why I did not reply all.<br>
</blockquote>
<br>
Well, thanks for saying it was OK for me to drag you into the sunshine so all can benefit from my stupidity. :)<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
WOW! Ok, I read that 10 times and have asked other perl programmers in the area to read it as well.<br>
</blockquote>
<br>
Other Perl programmers? Sweet! Are they on the Omaha Perl Mongers mailing list? Recruit them! :)<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
couple questions:<br>
1. How are the cases different? If ' ' is true and then both cases of your example should be the same.......right?!?! Obviously not since you changed the code but I don't know why.<br>
</blockquote>
<br>
' ' is very different from ''. :)<br>
<br>
I'm often a hunt and peck coder, so whatever perl does is the right answer. I don't know that there necessarily is a "why". (Other than "because that's what perl's C source code says" -grin-). So let's try some things...<br>
<br>
First, note that '' is false and ' ' is true.<br>
<br>
$ cat j.pl<br>
print '' ? 'yes ' : 'no ';<br>
print ' ' ? 'yes ' : 'no ';<br>
$ perl j.pl<br>
no yes<br>
<br>
But my thing was more like this:<br>
<br>
$ cat j.pl<br>
print ((not defined $j || 1) ? 'yes ' : 'no ');<br>
print ((not defined $j or 1) ? 'yes ' : 'no ');<br>
$ perl j.pl<br>
no yes<br>
<br>
-think,think,think-<br>
<br>
I'm betting this happens due to operator precedence. Reading "perldoc perlop" doesn't help me much at a glance since I'm not sure where 'defined' falls in the documented precedence order stack. But let's assume for a second that the precedence of 'defined' is higher than that of 'or' but lower than that of '||'. If that's true, then:<br>
<br>
not defined $j || 1<br>
<br>
would be processed as:<br>
<br>
$j || 1 true<br>
defined true true<br>
not true false<br>
<br>
So if 'defined' is a "nonassoc list operators (rightward)" then this is probably the correct answer and I feel all smart and stuff. :)<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
2. How do you get a eq to return ' ' ?<br>
</blockquote>
<br>
You don't? Apparently it returns '' if false, 1 if true:<br>
<br>
$ perl -d -e 1<br>
DB<1> x $j eq 'blah'<br>
0 ''<br>
DB<2> x $j eq ''<br>
0 1<br>
<br>
perldoc perlop says:<br>
<br>
Binary "eq" returns true if the left argument is stringwise equal to<br>
the right argument.<br>
<br>
And '' is false, and '1' is true, so there you have it... :)<br>
<br>
Did that help at all?<br></blockquote></div><br>Just a thought...<br><br>C<||> is higher then C<not> but<br>C<!> is higher then C<||> :P<br><br>If you put parentheses in the right place you get what you want.<br>
<br>
cat t.pl<br>print (((not defined $j) || 1) ? 'yes ' : 'no ');<br>print (((not defined $j) or 1) ? 'yes ' : 'no ');<br>
print ((! defined $j || 1) ? 'yes ' : 'no ');<br>
print ((not defined $j or 1) ? 'yes ' : 'no ')<br>yes yes yes yes<br><br><br>-- <br>Ted Katseres<br> ||=O=||<br>