What I am trying t odo with this script here is parse through a lot of data, and generate sql queries to update the db with values that i'm getting while this script's running. however, its very slow at the moment. i need suggestions on how to speed this thing up :)
#!/usr/bin/perl -w use strict; sub weekday { my ($day, $month, $year) = @_; if ($month < 3) { $month += 12; --$year; } my $tmp = $day + int((13 * $month - 27)/5) + $year + int($year/4) +- int($year/100) + int($year/400); return ($tmp % 7); } my $days_back = shift || 120; my ($start, $end); my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); my @days_month = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); my ($day, $month, $year) = (localtime)[3,4,5]; # Adjust year and month to readable stuff $year += 1900; $month++; $end = sprintf("%d-%02d-%02d", $year,$month,$day); $day -= $days_back; # If we went below 1, then we're into prev month # we while() here for when $days_back is larger than 1 month while ($day < 1) { # Don't forget to pad Feb for leap years if ($month == 3 && ($year % 4) == 0) { $days_month[1]++ } # deceremnt the month and calc the day $day += $days_month[--$month - 1]; if ($month < 1) { $month = 12; $year--; } } $start = sprintf("%d-%02d-%02d", $year,$month,$day); print"$start\n$end\n\n"; system("parsecache -f nlclick -s $start -e $end > nlclick.cache"); system("parsecache -f nlimage -s $start -e $end > nlopen.cache"); #print "$start\n$end\n\n"; for (my $i = 0; $i < $days_back; $i++) { my $wday = weekday($day, $month, $year); if ($wday > 0 && $wday < 6) { my $date = sprintf("%d%02d%02d", $year,$month,$day); #print "$date\n"; $_ = `report pattern --regex='nl=$date' --filter=nlimage --sum +only < nlopen.cache`; my ($opens) = /(.*)/; if (defined($opens)) { $_ = `report pattern --regex='nl=$date' --filter=standard +--sumonly < nlclick.cache`; my ($transfers) = /(.*)/; if (!defined($transfers)) { $transfers = 0 } printf("update msnNewsletter set open='%d', click='%d' whe +re dateCreated like '%d-%02d-%02d%%';\n", $opens, $transfers,$year,$m +onth,$day); } } if (++$day > $days_month[$month - 1]) { $day = 1; if (++$month > 12) { $month = 1; $year++; } } } unlink "nlclick.cache"; unlink "nlopen.cache";
if you need to look at the report tool that im using there, tell me and i will post that as well.

In reply to Parsing a lot of data. Very slow. Need suggestions by vxp

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.