On 6/5/07, <b class="gmail_sendername">Ricardo SIGNES</b> &lt;<a href="mailto:rjbs-perl-abe@lists.manxome.org">rjbs-perl-abe@lists.manxome.org</a>&gt; wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Did you know that when you write:<br><br>&nbsp;&nbsp;if ($string =~ /abcdef/) { ... }<br><br>It&#39;s the same as:<br><br>&nbsp;&nbsp;if ($string =~ m/abcdef/) { ... }<br><br>?</blockquote><div><br>Yeah.<br>&nbsp;<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Well, it is.&nbsp;&nbsp;The m is optional if you use // -- and I say &quot;if you use //&quot;<br>because you can use other delimiters:<br><br>&nbsp;&nbsp;if ($string =~ m|abcdef|) { ... } # some other repeated character<br>&nbsp;&nbsp;if ($string =~ m$abcdef$) { ... } # another repeated character
<br>&nbsp;&nbsp;if ($string =~ m{abcdef}) { ... } # an open/close pair of characters</blockquote><div><br>Unix 102: Avoiding the leaning toothpick syndrome. <br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Some pairs are magic, and have special meaning, like m?foo? -- but you can look<br>into that on your own.<br><br>Anyway, m// isn&#39;t the only thing that works this way.&nbsp;&nbsp;Just like // is secretly<br>m// in the context above, often &quot;&quot; is secretly qq&quot;&quot; and &#39;&#39; is secretly q&#39;&#39;.
<br><br>&nbsp;&nbsp;m&nbsp;&nbsp;- matching patern<br>&nbsp;&nbsp;qq - quoted string (interpolates scalars and arrays)<br>&nbsp;&nbsp;q&nbsp;&nbsp;- quoted string (no interpolation)<br><br>So!<br><br>&gt; $s = q@($t = $s) =~ s/\045/\100/g;<br>&gt; print &quot;#!/util/bin/perl\n\$s = q%$s%;$t&quot;;
<br>&gt; @;($t = $s) =~ s/\045/\100/g;<br>&gt; print &quot;#!/util/bin/perl\n\$s = q@$s@;$t&quot;;<br><br>The first @ begins a non-interpolated string, which ends at the next @.&nbsp;&nbsp;That<br>program says:<br></blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
&nbsp;&nbsp;$s = &#39;($t = $s) =~ s/\045/\100/g;&#39;<br>&nbsp;&nbsp;&nbsp;&nbsp; . &quot;\n&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp; . &#39;print &quot;#!/util/bin/perl\n\$s = ...<br><br>and so on.&nbsp;&nbsp;Does that help?</blockquote><div><br><div><br>
So I could use q&#39;&#39;, q@@, q||. q!! etc instead of q() just like I can use s&#39;&#39;&#39;, s@@@, s||| and s!!! instead of s/// ? <br>
</div>&nbsp;<br>--<br><br>Faber<br></div></div><br>