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

Can anyone tell me how to trim trailing double quotes?
What I currently have is this
$line =~ s/^\"//g;

The code about just strips leading double quotes. I can't seem to get rid of the last one.
Any help will be greatly apprciated.
Thanks,
Bobby

Replies are listed 'Best First'.
Re: Trimming trailing double quotes
by mpeters (Chaplain) on Jan 05, 2005 at 19:50 UTC
    Do you mean removing paried double quotes from a string?
    $line =~ s/"([^"])"/$1/;
    Or do you mean removing double quotes from the begining and end of a line?
    $line =~ s/^"(.*)"$/$1/;
      I was meaning your second statment. That worked fine.
      However, I'm still ending up with binary garbage in my array.
      Any advice on that?
      Thanks,
      Bobby

        What does "binary garbage" mean? ....remember, garbage in, garbage out. What does the input data look like, and what are you trying to get out of it?


        Dave

        What array?

Re: Trimming trailing double quotes
by DaWolf (Curate) on Jan 05, 2005 at 20:02 UTC
    The ^ sign tells the regex to trim only the first chacaracter of a line, as the $ sign tells to trim the last one. If you want to get rid of all double quotes you should remove it:

    $line =~ s/\"//g;

    Type perldoc perlre for more information.

    Regards,
Re: Trimming trailing double quotes
by perlsen (Chaplain) on Jan 06, 2005 at 07:25 UTC

    if you want to trim trailing double quotes

    u can change your regex as follows

    $line=' "the text" i found in "the" "line'; $line =~ s/(\w)"/$1/g; print $line;

    output:

    "the tex i found in "the "line

    regards,

    Senthil Kumar.k

      sorry the output i was mentioned in previous reply should be

      "the text i found in "the "line

      sorry for the previous suggetion of output

      but regex is correct

      thanks

      Senthil Kumar.k