In a fairly modern Perl, you could use each[0]: while (my ($index, $value) = each @array) { ... }
However, fixing your original problem is simple enough: #my @personen = @$personen; #Commenting this one out because I don't like having two variables with the same name. for ( my $i = 0; $i <= $#{$personen}; ++$i ) { print "Person $i: @{$personen->[$i]}\n"; } The main problem has in the print line; You were dereferencing a $person scalar that didn't exist! But even then, I'm guessing from your original program that $personen->[$i] (or $personen[$i], had you used @personen) would hold an arrayref, so you forgot a second level of dereferencing. In a slightly more idiomatic Perl, instead of the C-style for loop, you could write: for ( 0..$#$personen ) { ... # $_ has the index here! } I haven't used DBI all that much, but from what I recall selectall_hashref works something like this: my $personen = $dbh->selectall_hashref($sql, 'id'); for my $id ( sort { $a <=> $b } keys %$personen ) { say $id, ":\t", $personen->{$id}; } [0] http://perldoc.perl.org/functions/each.html On Wed, Feb 23, 2011 at 11:30 AM, Shawn H Corey <shawnhco...@gmail.com>wrote: > On 11-02-23 07:53 AM, HACKER Nora wrote: > >> my @personen = @$personen; >> foreach my $person ( @personen ) { >> print "<p>Dereferencing: @$person\n</p>\n"; >> } >> >> > Use Data::Dumper to inspect your data structures: > > use Data::Dumper; > for my $person ( @$personen ){ > print "Debug: $person = ", Dumper $person; > } > > > -- > Just my 0.00000002 million dollars worth, > Shawn > > Confusion is the first step of understanding. > > Programming is as much about organization and communication > as it is about coding. > > The secret to great software: Fail early & often. > > Eliminate software piracy: use only FLOSS. > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > >