serene_monk has asked for the wisdom of the Perl Monks concerning the following question:
I have this code for txt to csv
#!/bin/perl -w use strict; use warnings; use Text::CSV; my $csv = Text::CSV->new(); # creates object my $in_file = 'C:\Documents and Settings\x0199665\My Documents\tempora +ry.tl'; # input file open my $in_fh, '<', $in_file or die "could not open $in_file: $!\n"; + # assigns the file handler to input file as in_fh my @rows = (); + # keeps the count of rows in txt input file while( my $line = <$in_fh> ){ + # copies the line from our input chomp $line; push @rows, [ split m{ ,}msx, $line ]; + # splits the contents of $line seperated by comma and pushes it i +n array } close $in_fh or die "could not close $in_file: $!\n"; $csv->eol( "\n" ); + # after each line it gives a new line command print " Please enter the name of your csv file in which you will make +modifications "; print "\n"; my $out_file = <>; chomp $out_file; open my $out_fh ,">", $out_file or die "could not open $out_file: $!\n +"; for my $row ( @rows ){ $csv->print( $out_fh, $row ) or die "could not print to $out_file: $ +!\n"; # prints out the csv format } close $out_fh or die "could not close $out_file: $!\n"; my $rm_file = "temporary.tl"; unlink($rm_file) ; # this will remove t +he temporary file exit;
but this code puts " " in the csv . I don't know why , so how to remove them
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: txt to csv
by davido (Cardinal) on Jun 24, 2013 at 05:16 UTC | |
by serene_monk (Initiate) on Jun 24, 2013 at 05:23 UTC | |
by davido (Cardinal) on Jun 24, 2013 at 05:34 UTC | |
by torres09 (Acolyte) on Jun 24, 2013 at 05:44 UTC | |
by davido (Cardinal) on Jun 24, 2013 at 05:54 UTC | |
|
Re: txt to csv
by Tux (Canon) on Jun 24, 2013 at 06:28 UTC | |
|
Re: txt to csv
by kcott (Archbishop) on Jun 24, 2013 at 05:44 UTC |