Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!convex!usenet From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: shouldn't backslash really quote? Message-ID: <1991May22.202128.27037@convex.com> Date: 22 May 91 20:21:28 GMT References: <1991May22.175723.18174@uvaarpa.Virginia.EDU> Sender: usenet@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 65 Nntp-Posting-Host: pixel.convex.com From the keyboard of eichin@apollo.com: :The script (at the end of this message) prints: : :Line == <> :found x-pat :found x-brace-dollar-pat : :I would have expected it to print "found x-slash-dollar-pat" as well, :or at least threeslash... I get this output with VAX/BSD perl 3.041 :and 4.000, as well as Apollo Domain/OS perl 4.003. (I really do want :pattern matching, not equality checking, and (as the last if clause :shows) I should really be able to do this without eval.) Can anyone :explain to me why I can't simply backslash a dollar sign, as is :implied by the info file, : "Simply quote all the non-alphanumeric characters: : $pattern =~ s/(\W)/\\$1/g;" : :#!perl :$_='x_$foo'; :$pat = "foo"; :print "Line == <<$_>>\n"; :if(/x_.$pat/) { : print "found x-pat\n"; :} This was found, which makes sense. :if(/x_\$$pat/) { : print "found x-slash-dollar-pat\n"; :} Let's see. This becomes /x_\$foo/. In fact, if you use this pattern literally, then the match works fine. So I wonder whether it's a bug. Larry? Are you out there? Is the $foo screwing up and making it forget that \$ was quoted? :if(/x_\\$$pat/) { : print "found x-twoslash-dollar-pat\n"; :} This time you didn't escape the $, so it's anchoring at the end of the line. Shouldn't match. :if(/x_\\\$$pat/) { : print "found x-threeslash-dollar-pat\n"; :} There's a literal backslash here due to \\, so it shouldn't match. On the other hand, it maybe might have worked around the possible bug in x-slash-dollar-pat, but didn't. I guess that's good. :if(/x_[\$]$pat/) { : print "found x-brace-dollar-pat\n"; :} Yes, and then there's that. It should match and did. I get the same behavior you describe, back down to 3.018 perl. So I guess I have the same questions you did. --tom -- Tom Christiansen tchrist@convex.com convex!tchrist "So much mail, so little time."