On Thu, 29 Jan 2009, Sven Schreiber wrote:
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.
Er, sorry, but what totally different thing? "A string with a
series name" is exactly what it gives you, no?
For example, in
<script>
open data4-1
list L = 1 2 3
loop foreach i L
print $i
endloop
</script>
the loop part is equivalent to typing
print price
print sqft
print bedrms
and in
<script>
open data4-1
list L = 1 2 3
loop foreach i L
print "$i"
endloop
</script>
the loop is equivalent to typing
print "price"
print "sqft"
print "bedrms"
I don't mean to be unhelpful, but I don't yet understand the
problem. It seems totally transparent to me ;-) (who wrote it!).
Allin.