Question : Directory Log Files

Greetings Perl Experts,
This is not a homework assignment.  I am attempting to accomplish the following:
I have 3 patterns that I need to grep for in gzipped files in the directory.
For 2/3 patterns, I need a tally for the number of occurrences.  For the third pattern, I need to sum all the numbers.  My problem is that I don't know how to call the array later in the script for processing as it is global to a foreach loop.  The array that I'm speaking about is @retrieved.

TIA

==begin code.pl
#!/usr/bin/perl
use strict;
use FileHandle;
my $gzgrep = "/usr/bin/gzgrep";
my $retrieved = "(10, 0) =";
my $play = "Play";
my $place  = "Sent*";

my @tfiles = glob ('app.*.trace.gz');
my @lfiles = glob ('app.*.log.gz');

foreach my $tfile(@tfiles) {
  my @play = `$gzgrep '$play' $tfile`;
  my $playvalue = @play;
  print "$tfile Total Messages listened to: $playvalue\n";
}

foreach my $lfile(@lfiles) {
  my @retrieved = `$gzgrep '$place' $lfile`;
  my  @place = `$gzgrep '$place' $lfile`;
  my $retrievedvalue = @retrieved;
  my $placevalue = @place;
  print "$lfile Total messages retrieved: $retrievedvalue\n";
  print "$lfile Total Messages deposited: $placevalue\n";
}
==end code.pl

Answer : Directory Log Files

#!/usr/bin/perl
use strict;

my $gzgrep = '/usr/bin/gzgrep';
my $retrieved = "(10, 0) =";
my $play = 'Play';
my $place = 'Sent';
foreach my $tfile ( ){
  my $playvalue = () = `$gzgrep '$play' $tfile`;
  print "$tfile Total Messages listened to: $playvalue\n";
}
foreach my $lfile ( ){
    my $i=0;
    for( `$gzgrep '$retrieved' $lfile` ){
        $i += $1 if /\(10, 0\) = (\d+)/;
    }
    my $placevalue = () = `$gzgrep '$place' $lfile`;
    print "$lfile Total messages retrieved: $i\n";
    print "$lfile Total Messages deposited: $placevalue\n";
}
Random Solutions  
 
programming4us programming4us