in reply to Re^2: Search Engine Output needs sorting
in thread Search Engine Output needs sorting

Using @array in scalar context gives the number of elements in the array whereas $#array gives the index of the last element.

knoppix@Microknoppix:~$ perl -E ' > @array = ( 1 .. 5 ); > say qq{@array}; > say scalar @array; > say $#array;' 1 2 3 4 5 5 4 knoppix@Microknoppix:~$

I hope this is helpful.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^4: Search Engine Output needs sorting
by Anonymous Monk on May 28, 2011 at 14:04 UTC

    Thanks for clear explanation. Does ^# give the index of the first element? Don't why you'd need it, just curious.

Re^4: Search Engine Output needs sorting
by Anonymous Monk on May 28, 2011 at 14:12 UTC

    Reply didn't work... Does ^# give first index? Don't know why you'd need, but curious.

      Interesting piece of lateral thinking but, no!

      By default, array subscripts are zero based in Perl so the first index is 0 and first element is $array[ 0 ]. You could change that behaviour by altering a Perl built-in variable but its side effects can be unexpected and its use is deprecated so you *really* don't want to go there and I won't even tell you which variable it is :-)

      Cheers,

      JohnGG