[Pdx-pm] for vs foreach question
Jeff Zucker
jeff at vpservices.com
Wed Dec 10 13:00:30 CST 2003
Thomas Keller wrote:
> Hi all,
> I thought the "foreach" keyword was a synonym for the "for" keyword.
> So I'm perplexed why the following loops don't give the same output:
First, I think if you add "each" to the "for" in the first loop, it will
continue to work and if you take off "each" from the second loop, it
will continue to not work. The use of "for" or "foreach" is not
relevant to your problem.
Here is the second loop written correctly with more legible variable
names so you can see what's going on:
my $table = $aref;
for my $row (@$table) {
foreach my $column (@$row) {
print $column, " ";
}
print "\n";
}
Write back if that doesn't clarify things for you.
--
Jeff
More information about the Pdx-pm-list
mailing list