develooper Front page | perl.beginners | Postings from May 2012

Unique Array Help?

Thread Next
From:
Omega -1911
Date:
May 17, 2012 16:46
Subject:
Unique Array Help?
Message ID:
CAG3AkZdUZhwps-BnO-Hk9EShQ+d-4Uzys_NUT7HtYtXMHWA-ug@mail.gmail.com
Hello all -

While trying to create a script that generates a graph, I am at a loss
for a workable solution. What I need to be able to do in the code
below is add the results from the select statement before pushing the
data into an array. For example, the database contains the following
data:

EMPLOYEE_ID - HOURS_WRKD - DATE
--------------------------------------------------------
David - 8.5 - 1336432429
Marty - 7.5 - 1336432429
David - 5.0 - 1336432429
Steve - 8.0 - 1336432429
Elana - 6.5 - 1336432429
Marty - 8.0 - 1336432429

What I need to be able to do is add the employee's total hours before
pushing it into the array. As such, the following is what would be
pushed into the arrays below:

David - 13.5 - 1336432429
Marty - 15.5 - 1336432429
Steve - 8.0 - 1336432429
Elana - 6.5 - 1336432429

--------%<------ACTUAL CODE ------------%<-----------------
my $dbh = DBI->connect( "dbi:SQLite:dbname=$database_name", "", "" );
  my $all = $dbh->selectall_arrayref("SELECT employee_id, hours_wrkd,
date FROM data WHERE date >= $date_then AND date <= $date_now ORDER BY
hours_wrkd DESC" );
  foreach my $row (@$all)
  {
    ($employee_id, $hours_wrkd, $date) = @$row;
    print "\n\n$employee_id, $hours_wrkd, $date \n";
    push(@DATABASE_NAMES, $employee_id);
    push(@DATABASE_HOURS, $hours_wrkd);
  }
-------------------------------------------------------------------------
Thanks for any help! - David

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About