Hi all
i am having a problem reading from an array. i wrote this script to query
a database, get a certain record and based on the number of
records returned write to a file 1.the unixtime, 2.the number of records
in asteriks (ex. *** for 3 records) and 3.the number of records in digit
form.

i have the script querying every hour for the last 2 hours and the
feeding the hour, asteriks, and number of records into an array (@result)
and then i want to print each $result[1..#] into an html file. for reasons
unclear to me i receive the exact same hour record ($starthour) for each
returned query and then only one asterik for the first record and two for
the second for the number of records returned and then that number in
digit form
(ex:            1005802873      *  1
                1005802873      ** 2 )
but this result inaccurate, if i only query one hour back and dont save
the results in @result i receive an accurate result. can someone point me
in the right direction as to why this is happening. please note
this is my first real perl script and is probably hard to read, any
suggestions on how to improve readability will be greatly appreciated.

thanks alot,
        josh
==========================below is the script========================
#/usr/bin/perl -w
use strict;
use DBI;
use Time::Local;

my ($database, $user, $password, $hostname, $dbh, $sth, $starthour, $rc);
my ($numrows, $final, $item, $mailin, $endday, $time);
my (@result, @info);
$database = "sendmail";
$user = "josh";
$password = "buzaglo";
$hostname = 'katan';


#this gets time and converts it to unixtime
my
($time,$dateout,$day,$sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,$dst);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$time = timelocal($sec,$min,$hour,$mday,$mon,$year);
$starthour = ($time - 3600);
$endday = ($time - 7200);

# connect to db
if (not $dbh = DBI-> connect
("dbi:mysql:database=$database;host=localhost",
        "$user", "$password"))
        {
        print "unable to connect to $database $!";
        }

sub select
 {
   my ($query) = @_;
 $sth = $dbh->prepare($query);
    if (not $sth)
    {
     print "problem with statement handle $!\n";
    }
 $rc = $sth->execute();
    if (not $rc)
    {
        print "problem executing $!\n";
    }
 $numrows == 0;

while ( my @row = $sth->fetchrow_array ) {
    foreach $item (@row) {
$numrows++;
    $final = ("*" x $numrows);
    push(@result, $starthour, $final, $numrows);
        }
     }
}


$mailin = ("SELECT mto from log where mto like '%kata%' and datein between
$starthour and $time;");

 while ($time > $endday)
  {
    &select($mailin);
    $time = ($time - 3600);
  }


#print results
my $present = ($year + 1900);
 open(DAILY,">>$mday-$mon-$present-mailin.html") || die "can't open
daily.html $!\n";

# Content-type: text/html
 print DAILY <<EOL;

<HTML>
  <HEAD>
  <TITLE>Daily incoming mail stats by hour</TITLE>
  </HEAD>
  <BODY>
  <H1>hour      number of incoming emails</H1>
$result[0]      $result[1] $result[2]
$result[3]      $result[4] $result[5]
</BODY>
</HTML>

EOL


exit (0);
=====================================================================




-- 
  - josh
    N8MSO

20A8 2FC6 9099 D215 78F4 D005 B9F3 21C4 300C C25E    ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - [EMAIL PROTECTED] - tel: +972.58.520.636, http://www.tkos.co.il


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to