in reply to Help on displaying the output of two arrays
Note that I have added the Data::Dumper module in the code to inspect the structure of the hash table. I haven't tested the code, but I am confident that it would work. :-D#!/usr/bin/perl use strict; use Getopt::Long; use Data::Dumper; use IO::File; &GetOptions( 'd|date=s' => \(my $DATE), 'p|path=s' => \(my $PATH), 'h|help' => \(my $HELP) ); usage() if defined $HELP or ! (defined $DATE || defined $PATH); $PATH = "/Ack/$DATE" unless defined $PATH; my $ftpoutbound = "/homes/ftpoutbound.db"; my @FileList; opendir (DIR, $PATH) or die "Can't open dir $PATH $!"; while (my $f = readdir(DIR)) { next if -d $f; push @FileList, $f; } closedir DIR; # print Dumper(\@FileList); my %data; foreach my $file (@FileList) { my $f = new IO::File "$PATH/$file", "r" or die ("can't open $PATH/$file :$!"); while (<$f>) { my @rec = split /[\|\*~]/; if ($rec[5] eq "ZZ") { my $id = $rec[6]; $id =~ s/\s+//; $data{$id}{COUNT}++; } } } # print Dumper(\%data); # merge data into %data structure with values from FTP file my $f = new IO::File "$ftpoutbound", "r" or die "can't open $ftpoutbound :$!"; while (<$f>) { chomp; my @ftp_fields = split /;/; if (exists $data{$ftp_fields[0]}) { $data{$ftp_fields[0]}{TRANSPORT} = $ftp_fields[7]; } } undef $f; # display the results foreach (sort keys %data) { printf "%s|%s|%s\n", $_, $data{$_}{COUNT}, $data{$_}{TRANSPORT}; } sub usage { print <<EOL Usage: This program requires one argument, w/ an optional help argument. Options should be specified as follows: -d|date OPTIONAL Takes in the mmddyyyy format only. -p|path OPTIONAL Specifies a particular path. -h|help OPTIONAL Prints this message. example: ./TransactionsPerDay.pl --date 09152003 EOL ; exit(1); }
|
|---|