in reply to Perl MySQL Table into an array
my $struct = $sth->fetchall_hashref('extracted_ads_id'); # $struct will look like { foo => { extracted_ads_id => foo, prop_street_no => 12, prop_stree +t_name => 'blah' } bar => { extracted_ads_id => bar, ..... } # access like $struct->{foo}->{prop_street_no}
The hashref struct from DBI generally works but is almost never what you really want. To get a hash of array refs do:
my $h; while ( my $row = $sth->fetchrow_arrayref() ) { $h->{$row->[0]} = [ @row[1,2] ]; } # $h will look like { foo => [ 12, blah ], bar => [ .... } # access like $h->{foo}->[0] will give you street no.
I suggest you use Data::Dumper to look at what the return values look like if that does not make sense.
cheers
tachyon
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Perl MySQL Table into an array
by carric (Beadle) on Mar 14, 2004 at 02:23 UTC |