kevinw has asked for the wisdom of the Perl Monks concerning the following question:
and print it into file "outfile" in the following way:name1 1 2 3 4 typex name2 3 4 5 6 typey name3 2 3 3 1 typex name4 5 3 4 2 typez name5 9 8 2 1 typea
i'm trying to arrange it differently so that it's printed in the following format:typea name5 9 8 2 1 typex name1 1 2 3 4 name3 2 3 3 1 typey name2 3 4 5 6 typez name4 5 3 4 2
i'm currently using the following code to generate it:typex ...... typey ..... typea ..... typez ......
anyone have any suggestions as to how to print it in the other format? thanks in advancewhile (<TEMP>) { my @fields = split; my $key = pop @fields; my $line = [@fields]; push @{$data{$key}}, $line; } close TEMP; foreach my $key (sort keys %data); { print "$key\n"; my @lines = @{$data{$key}}; # list of lines, from hash foreach my $line (@lines); { my @fields = @$line; print "%s %d %d %d %s" @fields; } print "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Working with arrays
by VSarkiss (Monsignor) on Jul 24, 2002 at 15:29 UTC | |
by kevinw (Novice) on Jul 24, 2002 at 15:33 UTC | |
by VSarkiss (Monsignor) on Jul 24, 2002 at 15:41 UTC | |
by kevinw (Novice) on Jul 24, 2002 at 15:52 UTC | |
|
Re: Working with arrays
by vladb (Vicar) on Jul 24, 2002 at 15:08 UTC | |
by kevinw (Novice) on Jul 24, 2002 at 15:14 UTC | |
|
Re: Working with arrays
by krujos (Curate) on Jul 24, 2002 at 15:11 UTC | |
by kevinw (Novice) on Jul 24, 2002 at 15:16 UTC |