Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: how to state this by REL

by pg (Canon)
on Nov 09, 2005 at 06:57 UTC ( #506990=note: print w/ replies, xml ) Need Help??


in reply to how to state this by REL

The regexp is correct. The problem is your string. Use single quote instead of double quote, to avoid interpolation. Try this code:

{ my $name = "s@--__"; print $name, "\n"; if ($name =~ /\A[a-zA-Z][\w.-]*\z/) { print "match\n"; } else { print "not match\n"; } } { my $name = "s!!!@@@___"; print $name, "\n"; if ($name =~ /\A[a-zA-Z][\w.-]*\z/) { print "match\n"; } else { print "not match\n"; } } { my $name = 's@--__'; print $name, "\n"; if ($name =~ /\A[a-zA-Z][\w.-]*\z/) { print "match\n"; } else { print "not match\n"; } } { my $name = 's!!!@@@___'; print $name, "\n"; if ($name =~ /\A[a-zA-Z][\w.-]*\z/) { print "match\n"; } else { print "not match\n"; } }

Which prints:

Possible unintended interpolation of @___ in string at math1.pl line 1 +1. s-__ match s!!!@@ not match s@--__ not match s!!!@@@___ not match


Comment on Re: how to state this by REL
Select or Download Code
Re^2: how to state this by REL
by whatluo (Novice) on Nov 09, 2005 at 08:08 UTC
    >The regexp is correct. The problem is your string. Use single >quote instead of double quote, to avoid interpolation. Yes, I got it, Now I use single quote to make it happy, and I want to know what's really means as to \w in perl, do it include @ ! or not? Thanks for the info.
      According to the perlre documentation, it doesn't:
      A "\w" matches a single alphanumeric character (an alphabetic character, or a decimal digit) or "_", not a whole word.

      Arjen

      All that is gold does not glitter...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://506990]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2014-12-29 11:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (186 votes), past polls