in reply to Working With Arrays and Files
Let me know if you can't follow the data-structure stuff. I've tried not to use any shortcuts, but I know it can be confusing at first. --Dave;my %data = (); # get the data while (<TEMP>) { my @fields = split; # get fields my $key = pop @fields; # remove rightmost my $line = [@fields]; # $line is ref to list of fields push @{$data{$key}}, $line; # add to list of lines, in hash } close TEMP; #now print it: 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; # list of fields, from array-ref my $text = join(" ", @fields); print "$text\n"; } print "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Working With Arrays and Files
by kevinw (Novice) on Jul 23, 2002 at 20:16 UTC | |
by dpuu (Chaplain) on Jul 23, 2002 at 21:18 UTC | |
by kevinw (Novice) on Jul 23, 2002 at 21:33 UTC | |
by dpuu (Chaplain) on Jul 23, 2002 at 21:36 UTC | |
by kevinw (Novice) on Jul 23, 2002 at 21:47 UTC |