in reply to Regular Expression Fun
What you wrote means, "do s/\d{10}//g and then return success if it failed." Although that sounds a little funny and is not what you intended, it could actually be useful. Perhaps this will help you conceptualize what is happening:
Of course if we really wanted that effect, we would probably want to avoid the easy-to-miss "!" and say either of the following:if ($string !~ s/\d{10}//g) { print "String unchanged: couldn't find 10 digits.\n"; # do stuff to deal with regex failure } else { print "All cases of 10 digits have been deleted.\n"; }
To achieve what you wanted, check out the other responses which have offered good solutions.if (not $string =~ s/\d{10}//g) { unless ($string =~ s/\d{10}//g) {
------------------------------------------------------------
"Perl is a mess
and that's good because the
problem space is also a mess." - Larry Wall
|
|---|