Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Reading File and Seperating into columns

by marinersk (Chaplain)
on Sep 25, 2013 at 16:10 UTC ( #1055709=note: print w/ replies, xml ) Need Help??


in reply to Reading File and Seperating into columns

Your friend is horribly misinformed. Without handling any special CSV rules, a simple conversion from pipe to comma looks like this:

my @inpelt = split /\|/, $inpbuf; my $outbuf = join ',', @inpelt;

or this

$trnbuf =~ s/\|/,/g;

That said, if Text::CSV has grown up enough to be fully functional (and I suspect it has), you are very, very well advised to use it.

The proposed, and essentially de facto, CSV standard has a fair number of special cases which a proper CPAN module should be handling for you. Rolling your own, such as using the shortcuts shown above, would only work if you were absolutely certain the data crossed none of the CSV special handling cases.

A programmer writes code that works in a year; a software engineer writes code that works in ten years.

Failing to use a fully functional CPAN module to handle the CSV special cases would be a fine example of programming, not engineering, in this context.

Cheers!


Comment on Re: Reading File and Seperating into columns
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (16)
As of 2014-12-19 18:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (91 votes), past polls