Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: CSV file with double quotes

by chrestomanci (Priest)
on Sep 14, 2011 at 15:19 UTC ( #925930=note: print w/ replies, xml ) Need Help??


in reply to Re^2: CSV file with double quotes
in thread CSV file with double quotes

The snippet my $row = $csv->getline ($fh) in the example reads a line from the source file, and intelligently splits it up into fields. The Text::CSV library knows how do do that and takes quotes and the like into account. The $row scalar that it returns is slightly misleading as it is actually an array reference to the fields it extracted.

The next line: s/,/~z~/g for @$row; iterates over each field in the row and performs your substitution.

Question to rahulr: Why do you want to replace commas with "~z~"? It looks like you are trying to escape them. If so what would you do if you encounter a real "~z~" in your input? You might want to re-think how you are processing your data so that escaping works properly.


Comment on Re^3: CSV file with double quotes
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2014-12-17 20:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (32 votes), past polls