Re: Splitting a CSV file at a variable number
- From: chas.owens@xxxxxxxxx (Chas Owens)
- Date: Fri, 29 Jun 2007 09:27:39 -0400
On 6/28/07, sum_duud <Turnbull.Glenn@xxxxxxxxx> wrote:
in essence I would like the perl script to output all the fourthsnip
column "0" values to a file called phase_0.csv and all the "1" values
to phase_1.csv etc.
use an array of file handles (warning, untested):
use strict;
use warnings;
open my $in, '<', "phase.csv" or die "Could not open phase.csv: $!\n";
<$in>; #discard first line
my @file = map {
open my $fh, '>', "phase_$_.csv"
or die "could not open phase_$_.csv: $!";
$fh
} 0 .. 20;
while (<$in>) {
chomp;
my ($x, $y, $z, $phase) =split /\s*,\s*/;
my $file = $file[$phase];
print $file "$x, $y, $z, $phase\n";
}
.
- References:
- Splitting a CSV file at a variable number
- From: Sum_duud
- Splitting a CSV file at a variable number
- Prev by Date: Re: How can i make a perl program lauch another perl program that takes options
- Next by Date: Re: How can i make a perl program lauch another perl program that takes options
- Previous by thread: Splitting a CSV file at a variable number
- Next by thread: problem printing contents of file in directory
- Index(es):
Relevant Pages
|