Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: substituting constants within regex?

by halley (Prior)
on Jul 09, 2007 at 13:46 UTC ( [id://625604]=note: print w/replies, xml ) Need Help??


in reply to substituting constants within regex?

Nobody's mentioned that '^M' isn't the way you express a newline. It looks like you're trying to remove all those ^Ms you see in your files. Those are not really "caret character" plus "letter m character" (which is what you describe), but a special character called a carriage return that just appear that way in editors.

People who see this problem are likely using some form of Unix. You likely have a program called dos2unix on your system. Use that on your files.

Barring that, here's a perl one-liner from the Unix prompt that will do the same thing.

% perl -pi~ -e 's/\r//' *.txt

If you really need to do this in your own code, the bit between the single quotes is useful to you.

Update: From above replies, it looks like you do know the difference between '^M' and '\r', but I hope the information is still useful for yourself or others.

--
[ e d @ h a l l e y . c c ]

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-20 02:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found