Theuerkorn Johannes wrote:

> Hello List,
> 
> i just got stuck with hashes, hashes of hashes and referenzes... I know i
> have to study a bit about all of that... :-( So i hope theres somebody who
> can tell me the way (or direction...) :-)
> 
> I have a mysql Table and want the values out of the table in a hash of a
> hash:
> 
> I have a timestamp in the table for each dataset and i want to be able to
> access each part of the dataset, ordered by timestamp and column name.
> Thats my Script:
> 
> #!/usr/bin/perl -w
> # Johannes Theuerkorn for use with Teres, SieMo etc
> # 06-2002 Bruchsal
> #
> 
> # strict for not making failures :-)
> use strict;
> # use DBI mod
> use DBI;
> 
> my $db = "DiREx";
> my $user = "username";
> my $pwd = "password";
> my $debug =0;
> 
> 
> # Datenbank-Verbindung aufbauen
> #my $dbh = DBI->connect( 'dbi:mysql:'.$db,$user,$pwd) ||
> my $dbh = DBI->connect( 'dbi:mysql:'.$db,$user,$pwd) ||
>      die "Canīt connect to MySQL-Server: $DBI::errstr\n";
> 
> my %test_timestamp;
> my %values;
> 
> my $sth=$dbh->prepare ("select tstamp,serial,retests,passfail from
> nt5340.board where serial='CN+/P8100672'");
> 
> $sth->execute;
> 
> while (my ($tstamp,$serial,$retests,$passfail)=$sth-> fetchrow_array){
> 
> %values=();

your problem is the above line! you have only one hash and your reference to 
it later in the code still refers to just one hash so once this is clear 
for each row, the previous content is gone so after the while loop, you 
will only see one (the last one) row in your foreach loop. if you were to 
say something like:

$test_timestamp{$tstamp} = { 
tstamp=>$tstamp,serial=>$serial,retests=>$retests,passfail=>$passfail };

i bet it will work the magic because you are creating one hash reference for 
each row instead of creating just one hash for all the rows.

david

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

Reply via email to