I have some questions about the following code snippet (using DBI to
connect to MySQL):

1. $prep_query="SELECT school_name,path from student_data where
student_id=$student_id";
2. $query=$dbh->prepare($prep_query);
3. $query->execute;
4. $temp=$query->fetchall_arrayref();
5. foreach my $row (@$temp) {
6.  ($school,$path)=@$row;
7. # Do stuff with each $school, $path here
8. }

1. Is there a nice way to combine lines 1-3 or 1-4 into one nice easy
statement?
2. Is line 4 fetchall_arrayref returning a pointer $temp which points to
the beginning of an array?
3. And then I access the elements of the array by using @$temp in line
5?
4. Is line five treating $row as a pointer to an array?
5. ... in order to break it up into the individual elements on line 6
with @$row?
6. Any easy ways to compact/clarify this code would be terrific, I do
this sort of thing a lot. I know that I can just make a subroutine out
of it and do some variable passing, but I am also looking for ways to
compact the code itself as well as really understand what is going on.

If I know I'm returning just one result, I use this:

$prep_query="SELECT school_name, path from student_data where
student_id=$student_id";
$query=$dbh->prepare($prep_query);
$query->execute;
($school,$path)=$query->fetchrow_array();

Any easier ways to compact this one would also be terrific.

Thanks in advance. Perl rocks.
    Pete

Reply via email to