I am trying to find a way to make this faster, it just takes way too long to run. its grabbing its data from flat files of csv data. trying to calculate the statistic its looking at for each hour of each day for all of the roughly 30 days we keep the logfile it grabs its data from. feel free to ask any questions and I'll try to answer when I get the chance.

#!/usr/bin/perl #pragmas use strict; use warnings; #modules use File::Find::Rule; #declaring global variables use vars qw/$reportfile $lastday @datadir @sites @dates %devicecount @ +workingdata/; #set up the datadir array @datadir = qw[/dir1 /dir2 /dir3 /dir4 /dir5 /dir6 /dir7]; #set up the last day variable for file::find::rule my $lastday = time()-86400; #get a list of sites { my %uniquehash; my @devicefilelist = File::Find::Rule->file()->name('*SomeText*')- +>mtime("<$lastday")->in(@datadir); foreach (@devicefilelist) { if (open FILE, "$_") { while (<FILE>) { my $firstsplit = (split /,/, $_)[2]; my $site = (split /M/, $firstsplit)[0]; $uniquehash{$site} = 1; } close FILE; } } @sites = sort keys %uniquehash; chomp @sites; } #get a list of dates { my %uniquehash; my @datefilelist = File::Find::Rule->file()->name('*SomeText*')->i +n(@datadir); foreach (@datefilelist) { my $date = (split /_/, $_)[1]; $uniquehash{$date} =1; } @dates = sort keys %uniquehash; } #get a device count for each site { my %uniquehash; my @devicecountlist = File::Find::Rule->file()->name('*Texthere*') +->mtime("<$lastday")->in(@datadir); foreach my $file (@devicecountlist) { if (open FILE, $file) { while (<FILE>) { if (!/SomethingIDontWant/ && !/SecondThingIdontWant/ & +& !/ThirdThingIdontWant/) { my $device = (split /,/, $_)[2]; $uniquehash{$device} = 1; } } close FILE; } } foreach my $site (@sites) { foreach (keys %uniquehash) { if (/${site}b/) { $devicecount{$site} ++; } } } } #the main statistics routine { my ($site, $devicecount, $value, $counter, @workingdata, @workingd +ay); my @allfilenames = File::Find::Rule->file()->name( qr/Site-Calls/ +)->in(@datadir); open REPORT, ">>", &gen_reportfile_name(); foreach my $date (@dates) { @workingday = grep /$date/, @allfilenames; @workingdata = (); foreach my $file (@workingday) { if (open CURRENT, $file) { while (<CURRENT>) { push @workingdata, $_; } close CURRENT; } } foreach (0..23) { my $hour = sprintf "%02d", $_; while (($site, $devicecount) = each %devicecount) { $value = 0; $counter =0; foreach (@workingdata) { if (/${date}-${hour}/ && /$site/) { my @Fld = split /,/; $value += $Fld[11]; $counter++; } } print REPORT "$site\t$bscount\t${date}-${hour}\t"; if ($counter == 0) {print REPORT "0\n"} &dividebyzero($counter, $value); } } } } #divide by 0 subroutine sub dividebyzero { if (($_[0] > 0) && ($_[1] > 0)) { print REPORT $_[1]/$_[0] . "\n"; } elsif (($_[0] > 0) && ($_[1] == 0)) { print REPORT "0\n"; } } #generate the reportfile name sub gen_reportfile_name { my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(ti +me); $reportfile = sprintf "/dirhere/%4d%02d%02dtalkpath", $year+1900,$ +mon+1,$mday; }


In reply to speed issues by vatheck

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.