Am 29.01.2009 22:30, Allin Cottrell schrieb:
It's a scalar (usually an integer, and for sure an integer in a
"foreach" loop); really could not be anything else. The variable
'i' is always accessible within a loop, in scalar contexts, as in
print i
X[i] = foo
and so on.
Sure, that's the intuitive part.
In a "foreach" loop the '$i' construction works by lookup: it
indexes into the relevant array of strings or variable names and
returns entry i at iteration i.
In other sorts of loops, '$i' just gives the string representation
of the current index value, as if you had done
sprintf foo "%d", i
See I guess it's exactly this double, context-dependent, meaning that I
find confusing. I associate $i with string representation, and then I'm
all baffled why that (in a foreach loop context) won't give me a string
with a series name, but some totally different thing.
Couldn't the two meanings be syntactically separated? Just a different
character perhaps?
thanks,
sven