in reply to Doublequotes in column

I hope improved...
#!/usr/bin/perl -w use strict; use warnings; open (my $IN, '<', "quote1.csv") or die "cannot open file1 $!\n"; open (my $OUT, '>', "quoteremoved.csv") or die "cannot open file3 $!\n +"; while (my $line=<$IN>) { $line =~ tr/"//d; #delete all " print $OUT $line; }
Update: I'm sure that some Monk will point out the silly error of my ways, but it doesn't appear to me that the %custom hash accomplishes much.

Update2: Oh, I see I misinterpreted some other posts. I guess the idea is to only remove the " characters from the 3rd field? I'm up too late... tomorrow is already here.

Replies are listed 'Best First'.
Re^2: Doublequotes in column
by BrowserUk (Patriarch) on Dec 03, 2011 at 11:36 UTC
    $Uni =~ tr/"//; # trailing 'd' has no meaning here $line =~ tr/"//; # this deletes all " characters

    Sorry, but that is just wrong.

    Without the "trailing d", tr/// counts, but otherwise does nothing:

    $s = '"bill","1","fred"';; $s =~ tr["][];; print $s;; "bill","1","fred" $s =~ tr["][]d;; print $s;; bill,1,fred

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      I'm sorry too. The 'd' does matter.
      I hit the post button too soon.
      I still haven't figured out what this %custom hash does. But it is 4 AM here....
Re^2: Doublequotes in column
by bluray (Sexton) on Dec 05, 2011 at 00:25 UTC
    Hi Marshall,

    I tried the code, but it didn't remove the double quotes when opened as text file. I tried it on the whole $line and on $Uni (3rd column). No effect. Then, I had to manually cut the 3rd column into a text file and open it in spreadsheet to get rid of the doublequotes. Basically, this file was created using text::CSV_XS with the option always_quote=>1. The reason I wanted to get rid of this double quote is that this created problems when column 3 is used to match with another file.

      Well, tr will remove the " characters, like below...
      tr is a simple minded critter, but it is faster than substitute.

      If you created this with Text::CSV, then I would use that to parse it back in. Normally, I don't think that you have to specify the XS version, if its there, then it gets used - to the best of my knowledge.

      I'm still on a marathon DB project, but my machine has to think for 4-5 hours about what I've done so far. But on this project, | is used as the CSV delimiter instead of "," and that often works out very well. Sometimes I also see || and that is ok too (in the split, you can specify /\|\|/ as the splitting regex. In the DB that I'm working with | is explicitly not allowed as a valid data field value and hence it can be used as a simple delimiter in the CSV format and the Text::CSV module is not needed. But mileage varies...

      #!/usr/bin/perl -w use strict; while (<DATA>) { tr/"//d; print; } # prints: # some,always,quoted stuff # more,stuff,like that __DATA__ "some","always","quoted stuff" "more","stuff","like that"