in reply to building a hash from a database

fetchrow_hashref(), like the name suggests, returns a hash reference (i.e. a reference to a hash). You are accessing it as if it were a hash. As bart suggests, if you Use strict and warnings, you would be aware of this error. Hash vs. hashref:
my %hash = (id => "123", fname => "Fred); my $hashref = \%hash; print "$hash{id}\n"; print "$hashref->{id}\n";