
Laurent_R
Enthusiast
Oct 23, 2012, 10:55 AM
Views: 657
|
|
Re: [skysurf] iterating through an array using XML::Simple
|
|
|
A short test under de Perl debugger:
DB<8> @c = qw /foo bar baz/ DB<9> x @c 0 'foo' 1 'bar' 2 'baz' DB<10> $i = 0 DB<11> print $c['$i'] foo DB<12> $i = 1 DB<13> print $c['$i'] foo DB<14> $i = 2 DB<15> print $c['$i'] foo DB<16> print $c[$i] baz As you can see, when I use '$i' as index of the array, I get only the first element of the array, irrespective of the value of $i, as if '$i' was evaluated to 0 in this context (which happens when you evaluate a string in a numeric context). You really need to remove the single quote marks. With double quote marks, it would work:
DB<17> print $c["$i"] baz I think that your use of an array slice is also probably an error. You should probably prefix your array name with $ instead of @ (on the line where you are using the $i subscript).
(This post was edited by Laurent_R on Oct 24, 2012, 2:21 AM)
|