rjuuser
Programmer
- Dec 2, 2008
- 5
Hello,
I have a .csv file (converted from MS Excel) and my intention is to write every line into a separate (new) file. What I'm basically doing is this
My question is how should I modify this code to be able to write every single line into a separate .csv file? The file names can be etc. from the first column of my data.
I have a .csv file (converted from MS Excel) and my intention is to write every line into a separate (new) file. What I'm basically doing is this
Code:
#!/bin/perl
use warnings;
use strict;
use Text::CSV_XS;
use Tie::Handle::CSV;
my $fh = Tie::Handle::CSV->new(csv_parser => Text::CSV_XS->new({binary => 1}),
file => 'myfile.csv',
header => 1);
my @data = <$fh>;
my $csv_line;
foreach $csv_line (@data) {
print "Var1" . ": " . $csv_line->{'Variable1'} . "\n";
print "Var2" . ": " . $csv_line->{'Variable1'} . "\n";
}
close $fh;
My question is how should I modify this code to be able to write every single line into a separate .csv file? The file names can be etc. from the first column of my data.