wolverina has asked for the wisdom of the Perl Monks concerning the following question:

Anyone know how i can strip the parantheses off one line but leave them on other lines in a script? I want to strip them off this line: $url = "(http://www.somewebsite.com)"; but leave them on subsequent lines:
$url = $q->param('url'); $title = $q->param('title');
I tried this:
$text =~ s/\(//g; $text =~ s/\)//g;
but it gets rid of all parantheses in the script. Any idea's?
Lisa

Title edit by tye

Replies are listed 'Best First'.
Re: stripping parentheses from only one line
by FamousLongAgo (Friar) on Jan 03, 2003 at 05:11 UTC
    If the URL is always the same, try this:
    my $url = 'http://www.alwaysthesame.com'; s/"\($url\)"/"$url"/g; # match all occurences
    If the URL could be anything, try this:
    s|"\((http://[^)]+)\)"|"$1"|g;
    If you post more details about your data and the problem you are trying to solve, I'm sure we can come up with a more helpful solution.


Re: stripping parentheses from only one line
by Paladin (Vicar) on Jan 03, 2003 at 04:36 UTC

    What exactly does $text contain? And where is that URL that you want the ( and ) removed from in $text?

    If you just want to remove the first ( and first ) in $text, try:

    $text =~ s/\(//; $text =~ s/\)//;
Re: stripping parentheses from only one line
by jdporter (Paladin) on Jan 03, 2003 at 04:36 UTC
    Pardon me for suggesting the obvious, but, what about doing it by hand, in your favorite text editor?

    jdporter
    The 6th Rule of Perl Club is -- There is no Rule #6.