in reply to Re^3: Last undefines a for loop's itererator?
in thread Last undefines a for loop's itererator?
I would like foreach to unset its iterator variable if and only if it loops through the entire list without encountering last.
It doesn’t unset the iterator, it restores it. But people already get bitten by retained values of $1 and friends when a pattern with capturing parens failed to match. Do you really want to perpetuate this pattern into such a common construct as foreach?
If you want to retain the value, save it. It’s not hard, it makes it explicit what’s going on, and it lets foreach follow consistent mechanics with fewer surprises.
Makeshifts last the longest.
|
|---|