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

Thanks for the insightful tip! However I'm not sure what that changes, since it was working before. Did I over compensate using the 'defined' function (which I used when I saw the uninitialized error)? <\p>

I haven't encountered the $# before, does @ not work? Thanks again!

  • Comment on Re^2: Search Engine Output needs sorting

Replies are listed 'Best First'.
Re^3: Search Engine Output needs sorting
by johngg (Canon) on May 28, 2011 at 13:17 UTC

    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

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

      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