Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Replace Character Symbols with White Space

by davido (Cardinal)
on Jun 25, 2012 at 16:09 UTC ( [id://978219]=note: print w/replies, xml ) Need Help??


in reply to Replace Character Symbols with White Space

The tr/// operator (perlop).

$string =~ tr/+/ /;

Example:

perl -e '$string = "+=+=+=+"; $string =~ tr/+/ /; print "($string)\n"; +'

...the output...

( = = = )

If it's possible that your data has legitimate '+' characters (perhaps escaped, or quoted), then you'll have to use a more elaborate solution.

I think that perlintro is required reading for anyone new to Perl, and while the tr/// operator isn't discussed therein, the s/// is. The s/// operator could be used (less efficiently than tr///) like this: s/[+]/ /g. So after reading through perlintro, while you might not have discovered the most efficient way of doing it, you would have gotten a good start toward coming up with a reasonable way of doing it.


Dave

Log In?
Username:
Password:

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

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

    No recent polls found