in reply to Re^3: Text to CSV with user input comma
in thread Text to CSV with user input comma
This is what I am doing#!/usr/bin/env perl use Text::CSV; my $csv = Text::CSV->new(); open(my $in_fh, "<", "temporary.tl") or die "please create your temporary file: $!"; 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 ]; + } 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"; } close $out_fh or die "could not close $out_file: $!\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: Text to CSV with user input comma
by Tux (Canon) on Jun 28, 2013 at 08:14 UTC | |
by shushant (Novice) on Jun 28, 2013 at 08:30 UTC | |
Re^5: Text to CSV with user input comma
by hdb (Monsignor) on Jun 28, 2013 at 08:28 UTC | |
by shushant (Novice) on Jun 28, 2013 at 08:37 UTC | |
by hdb (Monsignor) on Jun 28, 2013 at 08:56 UTC |
In Section
Seekers of Perl Wisdom