 |
|
Home:
Need a Custom or Prewritten Perl Program?:
I need a program that...:
Re: [syedarshi] csv parsing:
Edit Log
|
|

shest75
Novice
Oct 27, 2009, 11:27 AM
Views: 1808
|
|
Re: [syedarshi] csv parsing
|
|
|
Bonjour,please try ( change file1.txt by the name of the file ) my %myhash; my $ligne; my $cpt; my $i; open FILE, "file1.txt" or die $!; while (<FILE>) { chomp($_); @ligne=split(/,/,$_); $cpt=split(/,/,$_); $i=2; while ( $i < $cpt-1 ) { $myhash{$ligne[0]}->{desc}=$myhash{$ligne[0]}->{desc}.",".$ligne[$i]; $i++;} $myhash{$ligne[0]}->{mesh}=$myhash{$ligne[0]}->{mesh}.",".$ligne[$cpt-1]; } foreach my $key ( sort keys %myhash ) { my $value = $myhash{$key}; $myhash{$key}->{desc} =~ s/,//; $myhash{$key}->{mesh} =~ s/,//; print "$key,$myhash{$key}->{desc},$myhash{$key}->{mesh}\n"; } perl file.pl > result.txt to have the result in a file.
(This post was edited by shest75 on Oct 27, 2009, 11:54 PM)
|
|
|
Edit Log:
|
|
Post edited by shest75
(Novice) on Oct 27, 2009, 11:31 AM
|
|
Post edited by shest75
(Novice) on Oct 27, 2009, 11:53 PM
|
|
Post edited by shest75
(Novice) on Oct 27, 2009, 11:54 PM
|
|
|  |