Joseph Paish <[EMAIL PROTECTED]> wrote:
[snip]
: # everything works well up to here !!!!!!!!
:
: # what i want to do is loop through the sorted unique part
: numbers array and print out all the array elements in
: @all_of_them that have a part number that matches that
: unique value. i then move onto the next unique part number
: and do the same thing
[snip]
#!/usr/bin/perl
use strict;
use warnings;
# Create Data Structure (Hash of Arrays)
my %parts;
while ( defined( my $line = <DATA> ) ) {
my $part_number = ( split ' ', $line )[3];
push @{ $parts{ $part_number } }, $line;
}
# Print Report sorted by Part Numbers (alphanumeric)
foreach my $part_number ( sort keys %parts ) {
print @{ $parts{ $part_number } }
}
__DATA__
03/06/1997 sold 1000 widget1 0.230 0.00
03/06/1997 sold 1000 widget3 0.230 0.00
03/06/1997 sold 1000 widget1 0.230 0.00
03/06/1997 sold 1000 widget2 0.230 0.00
prints:
03/06/1997 sold 1000 widget1 0.230 0.00
03/06/1997 sold 1000 widget1 0.230 0.00
03/06/1997 sold 1000 widget2 0.230 0.00
03/06/1997 sold 1000 widget3 0.230 0.00
Array of unique part numbers: keys %parts
Sorted Array of unique part numbers: sort keys %parts
More on Hash of Arrays(HoA): perldsc
HTH,
Charles K. Clarkson
--
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>