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

Re: Split a string to remove quotes and parentheses

by graff (Chancellor)
on Feb 21, 2006 at 06:11 UTC ( [id://531622]=note: print w/replies, xml ) Need Help??


in reply to Split a string to remove quotes and parentheses

You say you are trying to "split" the string, but it looks like you just want to remove unwanted characters. Everyone has pointed out variations on  s/[()"]+//g which certainly works.

Another way is the "tr" operator, which simply does character transliterations. In this case, you can "transliterate" the unwanted characters to nothing -- i.e. delete them:

my $string = '"(test123)"'; $string =~ tr/()"//d;
This is a simpler operation than regex substitution, so if your code needs to do this a lot, you could see a performance difference.

Replies are listed 'Best First'.
Re^2: Split a string to remove quotes and parentheses
by Anonymous Monk on May 31, 2016 at 13:34 UTC
    I have a similar problem to the one presented here. I have a string with dates and alternative representation of those dates in parentheses. E.g., .....5 June 2010 (June 10, 2005).... The tr solution given here is much simpler for my purposes. Thanks! Less is more!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-03-29 06:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found