New Perl user: using a hash of arrays
Posted
by Zach H
on Stack Overflow
See other posts from Stack Overflow
or by Zach H
Published on 2010-06-01T19:16:21Z
Indexed on
2010/06/01
19:23 UTC
Read the original article
Hit count: 426
I'm doing a little datamining project where a perl script grabs info from a SQL database and parses it. The data consists of several timestamps. I want to find how many of a particular type of timestamp exist on any particular day. Unfortunately, this is my first perl script, and the nature of perl when it comes to hashes and arrays is confusing me quite a bit.
Code segment:
my %values=();#A hash of the total values of each type of data of each day.
#The key is the day, and each key stores an array of each of the values I need.
my @proposal;
#[drafted timestamp(0), submitted timestamp(1), attny approved timestamp(2),Organiziation approved timestamp(3), Other approval timestamp(4), Approved Timestamp(5)]
while(@proposal=$sqlresults->fetchrow_array()){
#TODO: check to make sure proposal is valid
#Increment the number of timestamps of each type on each particular date
my $i;
for($i=0;$i<=5;$i++)
$values{$proposal[$i]}[$i]++;
#Update rolling average of daily
#TODO: To check total load, increment total load on all dates between attourney approve date and accepted date
for($i=$proposal[1];$i<=$proposal[2];$i++)
$values{$i}[6]++;
}
I keep getting syntax errors inside the for loops incrementing values. Also, considering that I'm using strict and warnings, will Perl auto-create arrays of the right values when I'm accessing them inside the hash, or will I get out-of bounds errors everywhere?
Thanks for any help, Zach
© Stack Overflow or respective owner