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

Hi, I have a file in the format:
"information","1234","3/23/2006 9:00:18AM","data","data","data","data" "information","1234","3/23/2006 9:00:18AM","data","data","data","data" "information","1234","3/23/2006 9:00:18AM","data","data","data","data"
I am trying to remove all the " characters with s/"//; but it isn't working... I've tried:
$file =~ s/"//;
and even:
for($i = 0; $i < scalar($#file + 1); $i++) { $data[$i] =~ s/"//; }
But I can't get it to work... please help! >_<

Replies are listed 'Best First'.
Re: Removing special characters
by borisz (Canon) on Mar 24, 2006 at 08:44 UTC
Re: Removing special characters
by Plato (Friar) on Mar 24, 2006 at 09:17 UTC
    Try this:
    #!/usr/bin/perl foreach my $file (<DATA>){ $file =~ s/"//g; print "$file"; } __DATA__ "information","1234","3/23/2006 9:00:18AM","data","data","data","data" "information","1234","3/23/2006 9:00:18AM","data","data","data","data" "information","1234","3/23/2006 9:00:18AM","data","data","data","data"

    Plato,
Re: Removing special characters
by tbone1 (Monsignor) on Mar 24, 2006 at 12:39 UTC
    By way of explaining the solutions, the s/a/b/ command will substitute text on the first instance that the regular expression matches. If you want to replace every instance, you need the 'g' (global) modifier: s/a/b/g

    Also, the y command replaces every instance by default but doesn't use regular expressions.

    --
    tbone1, YAPS (Yet Another Perl Schlub)
    And remember, if he succeeds, so what.
    - Chick McGee

      Thank you everyone for your replies and explanations!