Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Pattern mattching

by TedPride (Priest)
on May 30, 2005 at 08:36 UTC ( [id://461714] : note . print w/replies, xml ) Need Help??

in reply to Pattern mattching

my $c = '+000000'; print 'contains' if $c =~ /\+\d\d\d\d\d\d/;
Note that the s flag is for substitution. What you want is a match, so the s is left out. Also, as people have stated above, $a is a reserved variable, and while you can use it for this, you probably shouldn't. Also, as stated above, your regex can be shortened:
my $c = '+000000'; print 'contains' if $c =~ /\+\d{6}/;
And if you need to match exactly:
my $c = '+000000'; print 'contains' if $c =~ /^\+\d{6}$/; # or... print 'contains' if $c eq '+'.'0'x6;