Hi, I want to work with data from my database. The following select and dereferencing for display is fine:
my $sql = "select secondname || ' ' || firstname from supp_verantw_v"; my $sth = $dbh->prepare($sql); my $personen = $dbh->selectall_arrayref($sql) or die "geht net: $!\n"; my @personen = @$personen; foreach my $person ( @personen ) { print "<p>Dereferencing: @$person\n</p>\n"; } Now I want to alter the foreach-loop to a for-loop (because I need the index number) - but I don't know how to dereference over two levels: for ( my $i = 0; $i <= $#personen; ++$i ) { print "Person: $person->[$i]\n"; # ???????? } Error: Using an array as a reference is deprecated at /opt/freeware/apache/share/cgi-bin/edit/supportumg_neu.pl line 57. Global symbol "$person" requires explicit package name at /opt/freeware/apache/share/cgi-bin/edit/supportumg_neu.pl line 57. Bonus question: My main goal is to have a <select> field in a HTML form. The data for the options comes from the above select, the "values" are meant to be the IDs from the same table. My approach was to issue two separate select statements, one for the persons' names, another one for their IDs - that's why I needed the for-loop for the index. I also read on CPAN's documentation of DBI that by using selectall_hashref it should be possible to store the corresponding ID and name together in a hash, but again, I just didn't get it to work :-( Any help GREATLY appreciated - what a frustrating day today :-( Kind regards, Nora