[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: symbols in patterns interpreted *recursively*?

From: Mike Ayers
Subject: Re: symbols in patterns interpreted *recursively*?
Date: Mon, 07 Oct 2002 11:55:32 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.1) Gecko/20020826

RLMuller wrote:
Hi All,


Using a pattern I encountered behavior I didn't expect, as follows:
my $ABC = "abc";
$_ = $ABC;
print "\$ABC " . (/^$ABC$/? "matches" : "does not match") . " \"$ABC\"\n"; # Matches my $ABC_DEF = "abc\\def";
$_ = $ABC_DEF;
print "\$ABC_DEF " . (/^$ABC_DEF$/? "matches" : "does not match") . " \"$ABC_DEF\"\n"; # Doesn't match print "abc\\def " . (/^abc\\def$/? "matches" : "does not match") . " \"abc\\def\"\n"; # Matches If $ABC_DE's content is further interpreted, as seems to be the case, how do I stop it?

I'm feeling generous today, so I'm giving you not just an answer to your question, but two, count 'em, TWO helpful tips for a happy internet life!

print "\${ABC_DEF} " . (/^${ABC_DEF}$/? "matches" : "does not match") . " \"${ABC_DEF}\"\n"; # Matches!

Note the brackets around the variable name, without which Perl will assume the variable name ends with the first nonalphanumeric character, in this case '_'.

        Suggestion 1:
Don't send HTML, Rich text, or multipart MIME mail to technical mailing lists. It just upsets people, and most likely the person who can best answer your question will be one of the upset parties.

        Suggestion 2:
Send Perl questions to a Perl mailing list or newsgroup (heeding Suggestion 1 - I recommend comp.lang.perl.moderated). Normally you will get no answer to them here. I only looked at the problem because I thought it was a keyword substitution issue.

Don't use Perl variables named $Name, $Id or any other CVS keyword if you want to be able to archive your script with CVS.

        Have a nice day,


reply via email to

[Prev in Thread] Current Thread [Next in Thread]