<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
On 05/02/11 04:47, Anne Wainwright wrote:
<blockquote cite="mid:20110502134712.575481d3@ubuntu-laptop"
type="cite"><br>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<meta name="Generator" content="Microsoft Word 11 (filtered
medium)">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Verdana;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:Verdana;
color:windowtext;
font-weight:normal;
font-style:normal;
text-decoration:none none;}
@page Section1
{size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
</style>
<div class="Section1">
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;">Hi Anne<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;">I’ve just
started learning perl, and found your
contact details here (<a moz-do-not-send="true"
href="http://www.pm.org/groups/522.html">http://www.pm.org/groups/522.html</a>)
while looking for community help. It seems a bit out of
date, so please forgive
me if I’m knocking on the wrong door.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"><o:p> </o:p></span></font></p>
</div>
</blockquote>
B::Deparse's -p option is helpful here:<br>
<br>
<blockquote cite="mid:20110502134712.575481d3@ubuntu-laptop"
type="cite">
<div class="Section1">
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;">I was
exploring the “/x” regexp modifier, and
came upon some unexpected results. Upon closer inspection,
my problem lies with
the ternary operator. I can’t see why the following
results are
inconsistent ..<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;">
say
'1:'.( 'hello' =~ /h e l l o/
)?'true':'false'; # no '/x', no match</span></font></p>
</div>
</blockquote>
say((('1:' . ('hello' =~ /h e l l o/)) ? 'true' : 'false'));<br>
<br>
it evaluates the string '1:' concated with the return of the regex
evaluation, and '1:' is true. This can be seen by replace '1:' with
'0' which is false.<br>
<blockquote cite="mid:20110502134712.575481d3@ubuntu-laptop"
type="cite">
<div class="Section1">
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"><o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;">
say
'2:'.( 'hello' =~ /h e l l o/x
)?'true':'false'; # '/x' ignores spaces,
produces '1'</span></font></p>
</div>
</blockquote>
say((('2:' . ('hello' =~ /h e l l o/x)) ? 'true' : 'false'));<br>
<br>
While this is 'correct' as 'hello' does match /h e l l o/x, it isn't
why it returns true, it is again a concatenation of '2:' with the
result of the regex match, i.e. '2:1' which is also true.<br>
<br>
<blockquote cite="mid:20110502134712.575481d3@ubuntu-laptop"
type="cite">
<div class="Section1">
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"><o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;">
say
'3:'.( 'h e l l o' =~ /h e l l o/x )?'true':'false'; #
'/x' ignores
spaces, no match</span></font></p>
</div>
</blockquote>
say((('3:' . ('h e l l o' =~ /h e l l o/x)) ? 'true' : 'false'));<br>
<br>
The same as 1:<br>
<blockquote cite="mid:20110502134712.575481d3@ubuntu-laptop"
type="cite">
<div class="Section1">
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"><o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"> <span
style="background: none repeat scroll 0% 0% yellow;">say
'1:'.( 'hello' =~ /h e l l o/
).'.'; # no '/x', no match</span><o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"> <span
style="background: none repeat scroll 0% 0% yellow;">say
'2:'.( 'hello' =~ /h e l l o/x
).'.'; # '/x' ignores spaces, produces '1'</span><o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"> <span
style="background: none repeat scroll 0% 0% yellow;">say
'3:'.( 'h e l l o' =~ /h e l l o/x
).'.'; # '/x' ignores spaces, no match</span><o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;">
say
'1:'.( 'hello' =~ /h e l l o/ ) &&
'true.'; # no '/x', no match<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;">
say
'2:'.( 'hello' =~ /h e l l o/x ) &&
'true.'; # '/x' ignores spaces, produces
'1'<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;">
say
'3:'.( 'h e l l o' =~ /h e l l o/x ) && 'true.';
# '/x'
ignores spaces, no match</span></font></p>
</div>
</blockquote>
More of the same:<br>
<br>
<blockquote cite="mid:20110502134712.575481d3@ubuntu-laptop"
type="cite">
<div class="Section1">
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"><o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"> <span
style="background: none repeat scroll 0% 0% yellow;">say
'1:'.(( 'hello' =~ /h e l l o/ ) + 0)
.'.'; # no '/x', no match</span><o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"> <span
style="background: none repeat scroll 0% 0% yellow;">say
'2:'.(( 'hello' =~ /h e l l o/x ) + 0)
.'.'; # '/x' ignores spaces, produces '1'</span><o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"> <span
style="background: none repeat scroll 0% 0% yellow;">say
'3:'.(( 'h e l l o' =~ /h e l l o/x ) + 0)
.'.'; # '/x' ignores spaces, no match</span><o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;">
say
'1:'.(( 'hello' =~ /h e l l o/ ) +
0)?'true':'false'; # no '/x', no
match<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;">
say
'2:'.(( 'hello' =~ /h e l l o/x ) +
0)?'true':'false'; # '/x' ignores spaces,
produces '1'<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;">
say
'3:'.(( 'h e l l o' =~ /h e l l o/x ) +
0)?'true':'false'; # '/x'
ignores spaces, no match<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;">.. where
only the <span style="background: none repeat scroll 0%
0% yellow;">highlighted
sections</span> above yield the expected results. All
the others always return ‘true’.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;">If you
can’t help, then please point me in the right
direction for community support.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;">Many thanks
and kind regards<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;">DT<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"><o:p> </o:p></span></font></p>
</div>
</blockquote>
'.' is binding closer than the ternary operator, you want something
like:<br>
say '2:'.('hello' =~ /h e l l o/x ? 'true' : 'false'); <br>
to evaluate the regex match with the ternary operator, not the
result of the concatenation.<br>
<br>
<blockquote cite="mid:20110502134712.575481d3@ubuntu-laptop"
type="cite">
<div class="Section1">
<p class="MsoNormal"><font size="2" face="Verdana"><span
style="font-size: 10pt; font-family: Verdana;"><o:p> </o:p></span></font></p>
</div>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
Za-pm mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Za-pm@pm.org">Za-pm@pm.org</a>
<a class="moz-txt-link-freetext" href="http://mail.pm.org/mailman/listinfo/za-pm">http://mail.pm.org/mailman/listinfo/za-pm</a>
posts also archived on Mail Archive
<a class="moz-txt-link-freetext" href="http://www.mail-archive.com/za-pm@pm.org/">http://www.mail-archive.com/za-pm@pm.org/</a></pre>
</blockquote>
<br>
</body>
</html>