my $dbh = DBI->connect('...', { RaiseError => 0 }) or die "Unable to connect to datasource: $DBI::errstr\n"; my $sth = $dbh->prepare('SELECT PK, Name, Memo...'); or die "Unable to prepare query statement: $DBI::errstr\n"; my $rv = $sth->execute() or die "Unable to execute query statement: $DBI::errstr\n"; my $data = $sth->fetchall_arrayref; my %hash = %{ &checksums($data) }; # some time later... foreach(@$data) { print "PK:\t", $_->[0], "\t"; print "Name:\t", $_->[1], "\t"; print "Digest:\t", $hash{$_->[0]}, "\n"; } sub checksums { my $recordset = shift; my %checksums; foreach(@$recordset) { $checksums{$_->[0]} = &digest($_->[2]); } return \%checksums; } #### my @data; while($sth->fetch) { push @data, { PK => $_->[0], Name => $_->[1], Memo => $_->[2], Digest => &digest($_->[2]) }; } # some time later... foreach(@data) { print "PK:\t", $_->{PK}, "\t"; print "Name:\t", $_->{Name}, "\t"; print "Digest:\t", $_->{Digest}, "\n"; }