What are you entering into $pattern?
Multiple patterns:
jondev:/home/jondev/begperl/chp7> matchtest1.pl
Enter a regular expression:
\b\w{3}\b
\b\w{3}\b found in 1: A silly sentence (495,a) *BUT* one which will be useful. (3)
$& = 495
jondev:/home/jondev/begperl/chp7>
>>>
jondev:/home/jondev/begperl/chp7> matchtest1.pl
Enter a regular expression:
s\w+
s\w+ found in 1: A silly sentence (495,a) *BUT* one which will be useful. (3)
$& = silly
jondev:/home/jondev/begperl/chp7>
>>>
jondev:/home/jondev/begperl/chp7> matchtest1.pl
Enter a regular expression:
[^0-9 ^A-Z]\w+
[^0-9 ^A-Z]\w+ found in 1: A silly sentence (495,a) *BUT* one which will be useful. (3)
$& = silly
jondev:/home/jondev/begperl/chp7>
>>>
jondev:/home/jondev/begperl/chp7> matchtest1.pl
Enter a regular expression:
[^0-9 ^A-Z ^a-z]\w+
[^0-9 ^A-Z ^a-z]\w+ found in 1: A silly sentence (495,a) *BUT* one which will be useful. (3)
$& = (495
jondev:/home/jondev/begperl/chp7>
>>>
#!/usr/bin/perl -w
#matchtest1.pl
use strict;
my($pattern);
$_ = '1: A silly sentence (495,a) *BUT* one which will be useful. (3)';
print "Enter a regular expression: ";
chomp($pattern = <STDIN>);
if (/$pattern/){
print "$pattern found in $_\n";
print "\$& = $&\n";
print "\$1 is '$1'\n" if defined $1;
#print "\$2 is '$2'\n" if defined $2;
#print "\$3 is '$3'\n" if defined $3;
#print "\$4 is '$4'\n" if defined $4;
#print "\$5 is '$5'\n" if defined $5;
}
else{
print "$pattern NOT found\n";
}