in reply to Reformat Text File
open( my $fh, $infile ) or die "Cannot open '$infile' for reading: $!\ +n"; my %data; while ( defined( $_ = <$fh> ) ) { chomp; my @line = split( $_, ',', 2 ); push @{$data{$line[0]}}, $line[1]; } close( $fh ); open( $fh, ">$outfile" ) or die "Cannot open '$outfile' for writing: $ +!\n"; foreach my $k ( sort keys %data ) { print $fh join( ',', $k, @{$data{$k}} ), $/; } close( $fh );
Now, if this is homework, I wouldn't turn that in - it'll be obvious you got help. If it's not homework, take the time to figure out what I did. The key is push @{$data{$line[0]}}, $line[1];.
Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
|
|---|