P
Paul Lalli
First, I know, - I *know* - one should not play with the $[ variable,
and I would never ever do so in "real" code. Another thread mentioned
the variable, and I was bored, so I started playing. That being said,
I see the following results:
$ perl -le'
$[ = 7;
@foo = qw/alpha beta gamma/;
print "$_ => $foo[$_]" for 0 .. $#foo;
'
0 => alpha
1 =>
2 =>
3 =>
4 => alpha
5 => beta
6 => gamma
7 => alpha
8 => beta
9 => gamma
I can understand positions 7-9 being set. 7 is the first position of
the array now. And I can understand position 4-6 being set. This is
for the "wraparound" feature that we normally see when $[ hasn't been
altered and we access negative indices . But can anyone explain to me
why the position 0 is set? (and yes, I know -w would give me three
"use of uninitialized" warnings for 1-3 above. Not relevant to my
question, so I omitted it).
I do not see any similar results when printing the values of, say -10
through 3 if $[ has not been altered. So I assume this is specific to
the 0th position, after $[ has been modified...
This is perl, v5.8.4 built for sun4-solaris
Paul Lalli
and I would never ever do so in "real" code. Another thread mentioned
the variable, and I was bored, so I started playing. That being said,
I see the following results:
$ perl -le'
$[ = 7;
@foo = qw/alpha beta gamma/;
print "$_ => $foo[$_]" for 0 .. $#foo;
'
0 => alpha
1 =>
2 =>
3 =>
4 => alpha
5 => beta
6 => gamma
7 => alpha
8 => beta
9 => gamma
I can understand positions 7-9 being set. 7 is the first position of
the array now. And I can understand position 4-6 being set. This is
for the "wraparound" feature that we normally see when $[ hasn't been
altered and we access negative indices . But can anyone explain to me
why the position 0 is set? (and yes, I know -w would give me three
"use of uninitialized" warnings for 1-3 above. Not relevant to my
question, so I omitted it).
I do not see any similar results when printing the values of, say -10
through 3 if $[ has not been altered. So I assume this is specific to
the 0th position, after $[ has been modified...
This is perl, v5.8.4 built for sun4-solaris
Paul Lalli