in reply to Re^2: Reading a array
in thread Reading a array

You're quite likely correct; it's just that from the code fragment given by the OP, I couldn't find where his array was being populated. I also tend to think that an event like $#arr1 giving an incorrect value is unlikely; I would expect that $#arr1 is among the Perl features least likely to have any bugginess. My thinking (I'm easily confused by symbolic references, so I'm likely wrong) is that $#arr1 isn't quite the same as scalar(@$arr1)-1.


Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

Replies are listed 'Best First'.
Re^4: Reading a array
by jethro (Monsignor) on Aug 08, 2008 at 16:30 UTC

    Exactly, if there is a @arr1 and you access it without any symbolic reference, then $#arr1 is scalar(@arr1)-1. Only @arr1 is accessed here, the value of $arr1 is irrelevant and isn't used at all

    If we use $arr1 (totally different variable from @arr1) as a symbolic reference, then

    @bingo=(1,2,3); $arr1='bingo'; print $#{$arr1}, scalar(@$arr1)-1, scalar(@bingo)-1;

    would print 222, as all three print expressions would be equivalent. In this case @arr1 is irrelevant and not used at all, only $arr1 as the symbolic reference and @bingo as the array