Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: s/// for \dOO for typos

by ig (Vicar)
on Oct 28, 2010 at 12:14 UTC ( [id://867992]=note: print w/replies, xml ) Need Help??


in reply to s/// for \dOO for typos [SOLVED]

I wondered about cases like 2o2 and 2O2. It was harder than I thought it would be to change these, but the following does:

while(<DATA>) { print; s/\b([\do]+)\b/(my $x = $1) =~ s!o!0!gi; $x;/gie; print "--> $_"; } __DATA__ lo123 asdf lone fs 2oo 3O7 o123 o123b 321o asf o987o 123 23o8 123 o4o4ooo

which produces

lo123 --> lo123 asdf lone fs --> asdf lone fs 2oo --> 200 3O7 --> 307 o123 --> 0123 o123b --> o123b 321o --> 3210 asf o987o 123 23o8 --> asf 09870 123 2308 123 o4o4ooo --> 123 0404000

Replies are listed 'Best First'.
Re^2: s/// for \dOO for typos
by wallisds (Beadle) on Oct 28, 2010 at 18:34 UTC
    Try this:

    #!/usr/bin/perl use strict; my $new = "100o798 boonanas woot!"; print "Original line: $new\n"; $new =~s/([0-9]+)o/$1\Q0\E/gi; print "With ~s: $new\n"; exit;


    Thanks,
    Dawn

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-20 03:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found