urgh..it's not homework...here's my example script...please help...
#!/usr/bin/perl
##BILLING PROGRAM##
use strict;
my(@data,@data2);
##open needed files to use in program
open(FILE, "../Counts/newdata.txt")
or die "Can't open file: $!\n";
open(FILE2, "../Counts/info.csv")
or die "Can't open file: $!\n";
##throw files into arrays and define arrays
chomp(@data = <FILE>);
chomp(@data2 = <FILE2>);
##define hash
my ($id,$name,$srid);
my %keyhash = ( $id => { NAME => $name,
SRID => $srid,
CSV => []
}
);
##populate arrays:
foreach ( @data ) {
##define variables
my ($id,$name,$srid) = split /,/;
# Add some error checking to make sure the
# hash key $id does not already exist
$keyhash{$id} = { NAME => $name,
SRID => $srid,
CSV => [],
}
}
##print unused ids from csv file
print "\n\nUnused ids from csv file\n";
print "--------------------------\n";
foreach ( @data2 ) {
my ($id,$name,$srid) = split /,/;
# Warn and do nothing if a record is found for which the
# $name is not already in %keyhash
unless ( defined( $keyhash{$name} ) ) {
warn "No such record $id!\n";
next;
}
push @{$keyhash{$id}{CSV}}, [ $name, $srid ];
}
##Finally, extract the number of records for each customer
##print column headers
print "\n\n";
print "Customer #of docs\n";
print "-------------------------\n";
# A little something to get the plurality correct
foreach ( keys %keyhash ) {
my $num = @{$keyhash{$_}{CSV}};
printf "%s %d\n",
$keyhash{$_}{NAME},
$num,
}
##just formatting by adding a couple returns at the end of the printou
+t
print "\n\n";
##my choice of data structures ( hashes instead of arrays ) is dependa
+nt
##on how we want to use the data later.
##close files
close (FILE);
close (FILE2);
##exit program
exit;
Here it is. Thanks for beating me up :) ..
|