execute($frm, $req_no); my $i = 1; while (my $row = $sth->fetchrow_hashref) { print "row ", $i++, "\n"; for my $col (keys %$row) { print "\..." />

Perl DBI dynamic fetchrow while loops?

" ); $sth->execute($frm, $req_no); my $i = 1; while (my $row = $sth->fetchrow_hashref) { print "row ", $i++, "\n"; for my $col (keys %$row) { print "\t$col is $row->{$col}\n"; } } } You may also want to set FetchHashKeyName to NAME_lc or NAME_uc when you create your database handle: my $dbh = DBI->connect( $dsn, $user, $pass, { ChopBlanks => 1, AutoCommit => 1, PrintError => 0, RaiseError => 1, FetchHashKeyName => "NAME_lc", } ) or die DBI->errstr.

" ); $sth->execute($frm, $req_no); my $i = 1; while (my $row = $sth->fetchrow_hashref) { print "row ", $i++, "\n"; for my $col (keys %$row) { print "\t$col is $row->{$col}\n"; } } } You may also want to set FetchHashKeyName to "NAME_lc" or "NAME_uc" when you create your database handle: my $dbh = DBI->connect( $dsn, $user, $pass, { ChopBlanks => 1, AutoCommit => 1, PrintError => 0, RaiseError => 1, FetchHashKeyName => "NAME_lc", } ) or die DBI->errstr.

(keys %$row) gives me this - Global symbol "%row" requires explicit package name at . /req. Pl – CheeseConQueso May 15 '09 at 16:56 The print in the for should be: print "\t$col is $row->{ $col }\n"; – Anon May 15 '09 at 17:27 Whoops, that is what I get for not testing.

– Chas. Owens May 15 '09 at 17:49 Could be worth mentioning to set FetchHashKeyName when calling DBI->connect to iron out gotchas with possibly-case-insensitive uppercase/lowercase column names being used as case-sensitive hash keys. So for instance I always connect specifying FetchHashKeyName => 'NAME_lc' so that the hash keys representing the column names are guaranteed to be lower case, even if the DB returns them CamelCased.

– araqnid May 15 '09 at 17:56 @araqnid I was adding that while you were leaving the comment. – Chas. Owens May 15 '09 at 18:56.

I wonder if this method would work for an empty table. The safest method to get the column metadata is not to look at the keys of the returned hashref (which might not exist) but rather play by the rules and use DBI provided attributes of $sth itself: $sth->{NAME}->i $sth->{NAME_uc}->i $sth->{NAME_lc}->i See the Metadata section of the DBI man page for details.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions