Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: txt to csv

by Tux (Abbot)
on Jun 24, 2013 at 06:28 UTC ( #1040375=note: print w/replies, xml ) Need Help??

in reply to txt to csv

Why only use the module for writing the CSV, and not for parsing? Parsing usually is the hard part.

If the space before the comma is to be removed on parsing, use the allow_whitespace attribute for that.

use Text::CSV; my $csv = Text::CSV->new ({ binary => 1, auto_diag => 1, # Have the module complain about errors allow_whitespace => 1, # allow 1 , 2 ,3 }); my $in_file = "C:/Documents and Settings/x0199665/My Documents/tempora"; open my $in_fh, "<", $in_file or die "could not open $in_file: $!\n"; my @rows; # Use Text::CSV (or Text::CSV_XS) to parse, not split while (my $row = $csv->getline ($in_fh) { push @rows, $row; } close $in_fh or die "could not close $in_file: $!\n"; # my $rows = $csv->getline_all ($in_fh); # would do all in one go print " Please enter the name of your csv file in which you will make +modifications: "; chomp (my $out_file = <STDIN>); open my $out_fh, ">", $out_file or die "could not open $out_file: $!\n +"; $csv->eol ("\n"); $csv->print ($out_fh, $_) for @rows; close $out_fh or die "could not close $out_file: $!\n";

Enjoy, Have FUN! H.Merijn

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1040375]
[erix]: who can explain to me why Primary Key Fragmentation (whatever it may be) might be a problem?
[jedikaiti]: Pretty!
[erix]: ( TBH, I think it's a load of bull -- but maybe I'm mistaken )
[erix]: Hey that's Hungary - wave down ambrus and tell him to reboot his systems!
[choroba]: it might be a problem if you expect to reach the maximal possible value soon without squashing the ids
[erix]: that's really impossible with bigint
[erix]: and the site is still only 'hopefully' active :)

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2017-06-23 15:45 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (550 votes). Check out past polls.