On 6/5/07, <b class="gmail_sendername">Ricardo SIGNES</b> <<a href="mailto:rjbs-perl-abe@lists.manxome.org">rjbs-perl-abe@lists.manxome.org</a>> 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> if ($string =~ /abcdef/) { ... }<br><br>It's the same as:<br><br> if ($string =~ m/abcdef/) { ... }<br><br>?</blockquote><div><br>Yeah.<br> <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. The m is optional if you use // -- and I say "if you use //"<br>because you can use other delimiters:<br><br> if ($string =~ m|abcdef|) { ... } # some other repeated character<br> if ($string =~ m$abcdef$) { ... } # another repeated character
<br> 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't the only thing that works this way. Just like // is secretly<br>m// in the context above, often "" is secretly qq"" and '' is secretly q''.
<br><br> m - matching patern<br> qq - quoted string (interpolates scalars and arrays)<br> q - quoted string (no interpolation)<br><br>So!<br><br>> $s = q@($t = $s) =~ s/\045/\100/g;<br>> print "#!/util/bin/perl\n\$s = q%$s%;$t";
<br>> @;($t = $s) =~ s/\045/\100/g;<br>> print "#!/util/bin/perl\n\$s = q@$s@;$t";<br><br>The first @ begins a non-interpolated string, which ends at the next @. 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;">
$s = '($t = $s) =~ s/\045/\100/g;'<br> . "\n"<br> . 'print "#!/util/bin/perl\n\$s = ...<br><br>and so on. Does that help?</blockquote><div><br><div><br>
So I could use q'', q@@, q||. q!! etc instead of q() just like I can use s''', s@@@, s||| and s!!! instead of s/// ? <br>
</div> <br>--<br><br>Faber<br></div></div><br>