You might find it simpler to process a single directory at a time. For example

#!/usr/bin/perl use strict; use File::Find::Rule; use IO::Uncompress::Bunzip2; use Time::Piece; use Time::Seconds 'ONE_DAY'; #use Data::Dump 'pp'; # build regex use Net::Netmask; my $ip = '72.46.130.0/24'; my $block = new Net::Netmask($ip); my $re = join '|', map { quotemeta } $block->enumerate(); #print $re; my $FMT = '%Y-%m-%d'; my $dateStart = '2017-12-01'; my $numberOfDays = 5; # array ref for dates my $dates = get_dates($dateStart,$numberOfDays); # Directories to search my @LogDir = qw( /cygdrive/c/Users/anon/Documents/logs/png1/ /cygdrive/c/Users/anon/Documents/logs/png2/ ); for my $path (@LogDir){ for my $ymd (@$dates){ my $dir = $path.$ymd; next unless (-d $dir); print "In directory '$dir'\n"; my @files = File::Find::Rule->file() ->name( '*.bz2','*.log' ) ->maxdepth(3) ->in($dir); for my $filename (@files){ searchForIP($filename,$re); } } } sub searchForIP { my ($filename,$re) = @_; print "--- Searching '$filename' ---\n"; my $fh; if ($filename =~ /bz2$/){ $fh = IO::Uncompress::Bunzip2->new($filename) or die "bunzip2 $filename: $IO::Uncompress::Bunzip2::Bunzip2Error +"; } else { open $fh,'<',$filename or die "Could not open $filename : $!"; } my $count = 0; while (<$fh>){ print "$filename:$.:$_" if /$re/; ++$count; } print "\n$count lines scanned\n"; } sub get_dates { my ($start,$days) = @_; my @dates; my $t = Time::Piece->strptime($start,$FMT); for (1..$days){ push @dates,$t->ymd; $t += ONE_DAY; } return \@dates; }
poj

In reply to Re^2: Process multiple directories by poj
in thread Process multiple directories 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.