in reply to strange syntax

Hello,

$#kbin gives the index of the last entry of array @kbin. Since @kbin is undefined, it is empty, and so the result is -1. 0 would be the first index of an non empty array.

If you use $#{$kbin}, you should get the index of the last entry of @{$kbin}, that is the array dereferenced by $kbin.

Replies are listed 'Best First'.
Re^2: strange syntax: $#array
by parv (Parson) on Jun 17, 2015 at 06:18 UTC

    On the same lines if last-index-of-array variable, $#x, is assigned -1, array becomes empty (mentioned in perldata) ...

    DB<1> @x = ( 1 , 2 ) DB<2> x @x 0 1 1 2 DB<3> $#x = -1 DB<4> x @x empty array DB<5>
Re^2: strange syntax
by grasshopper!!! (Beadle) on Jun 16, 2015 at 23:07 UTC

    Thank you for answering can you explain why $kbin = split( is used and not @kbin = split(

      That's probably just a mistake. Calling split in scalar context will assign the number of items produced by the split to the scalar, so $kbin will contain the number of items the split returns, not the items themselves. That might make sense in some cases, but not here, since $kbin is being used as if it's an array later.

      My first guess would be that this was written by a PHP programmer, since their arrays don't use a different sigil like Perl's do.

      Aaron B.
      Available for small or large Perl jobs and *nix system administration; see my home node.