in reply to Find odd/even elements of array
As a side note, you really don't want to get into the habit of sticking variable data directly into your SQL statements. Use placeholders instead.my @student_info = ("001","John","002","Mary","003","Tom"); my %hash = @student_info; say join ", ", sort keys %hash;
Taking all of the above into account, your posted code becomes something like:
my @student_info = ("001","John","002","Mary","003","Tom"); my %name_hash = @student_info; my $grade_sth = $dbh->prepare("select id from grades where id = ? and +grade = 'A'"); for my $student_id (sort keys %name_hash){ $grade_sth->execute($student_id); my $student_name = $name_hash{$student_id}; # do output here }
|
|---|