in reply to Finding the Remaining of Array by Slice - A quick way?
Is an array slice setting elements of @ar2 to elements of @ar1 using the values of @s1 as indices. To write it out longhand, it is doing:@ar2 = @ar1[@sl];
Now substitute in the values of @s1 elements:$ar2[0] = $ar1[ $s1[0] ]; $ar2[1] = $ar1[ $s1[1] ];
And we see why it failed -- the characters 'b' and 'd' cannot be used as the index of an array. Apparently from the output, perl was cast the chars to 0 and that's why both elements are 'a'.$ar2[0] = $ar1[ 'b' ]; $ar2[1] = $ar1[ 'd' ];
Argument "b" isn't numeric in array slice at /tmp/r line 10. Argument "d" isn't numeric in array slice at /tmp/r line 10.
|
|---|