in reply to Re: how do I manipulate data in csv file
in thread how do I manipulate data in csv file
#!/usr/bin/perl use Text::ParseWords; + use Data::Dumper; + use IO::File; #my $file = test.csv; + my $file = $ARGV[0]; my ($output_file) = ($file =~ /(.*)\./); + open(my $fh, '<', $file) or die "Can't read csv file '$file' [$!]\n"; + my $countlines = 0; my $countlines1 = 0; while (my $line = <$fh>) {while (my $line = <$fh>) { chomp $line; my @fields = Text::ParseWords::parse_line(',', 0,$line); + if($countlines >= 0 && @fields[0]==201120) {if ( @fields[1]==1){ $countlines1 = $countlines1 + 1;} $countlines++; } } print "$countlines\n"; print "$countlines1\n"; $yield = ($countlines1 / $countlines)*100 ; print $yield; }
Thank for your reply,it does not have to be the same csv file. Currently , my code able read one week only and print it volume and yield. I need some guides from you all.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: how do I manipulate data in csv file
by Tanktalus (Canon) on Jul 26, 2011 at 05:03 UTC | |
by Anonymous Monk on Jul 26, 2011 at 06:10 UTC | |
by Anonymous Monk on Jul 26, 2011 at 14:06 UTC |