Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Regular Expression Fun

by dvergin (Monsignor)
on Feb 26, 2002 at 20:09 UTC ( [id://147700]=note: print w/replies, xml ) Need Help??


in reply to Regular Expression Fun

You tried:     $string !~ s/\d{10}//g; and asked "why can't I just reverse it?" What you wrote did reverse something. But, as you say, not what you intended.

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:

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"; }
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 (not $string =~ s/\d{10}//g) { unless ($string =~ s/\d{10}//g) {
To achieve what you wanted, check out the other responses which have offered good solutions.

------------------------------------------------------------
"Perl is a mess and that's good because the
problem space is also a mess.
" - Larry Wall

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2024-04-25 01:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found