Your solution is not very efficient because it iterates too much unnecessarily. What you need is to build a hash table to store the necessary data before printing them at the end. Here's my attempt at your code...
#!/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); }
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


In reply to Re: Help on displaying the output of two arrays by Roger
in thread Help on displaying the output of two arrays by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.