Gossamer Forum
Home : General : Perl Programming :

Control Structres

Quote Reply
Control Structres
Is there any advantage or disadvantage for using for instead of while? Here's the scenario.

I want to extract information from the database, I could define all variables at the beginning with while or I could just point to various fields in the database with for. Example:
Code:
# while ($pointer = $sth->fetchrow_hashref) {
# $res_id = $pointer->{'id'};
# $res_type = $pointer->{'res_type'};
. . . . . .

Code:
for $record (@$records) {
print "$record->{'name_en'}";
. . . . . .
}

Now what I want to know is there any performance differene between the two? If I define the variables at the start, does that make it faster? Or by only dipping into and creating variables where I need them is faster?

Any info on this would be appreciated.

Thanks


- wil