http://qs321.pair.com?node_id=817637


in reply to Why is "for" much slower than "while"?

context, while is scalar, for is list, and readline reads the whole file in list context
$ perl -MO=Deparse -e" ++$counts{$_} for <IN>; " ; ++$counts{$_} foreach (<IN>); -e syntax OK $ perl -MO=Deparse -e" ++$counts{$_} while <IN>; " ++$counts{$_} while defined($_ = <IN>); -e syntax OK