in reply to basic question on split

perldoc length states:

Returns the length in characters of the value of EXPR. If EXPR is omitted, returns length of $_. Note that this cannot be used on an entire array or hash to find out how many elements these have. For that, use scalar @array and scalar keys %hash respectively.

So when you are doing

$restLength = length(@rest);
I think you mean (the scalar function being optional in this case):
$restLength = scalar @rest;

On another note there is not need to go through all the contortion of making your loop c-like. Something like:

for my $item (@rest) { print "$item": }
will work just as well, and relieve you of worrying about iterators.

update: I neglected to mention that your split is working fine, but that it was the length bit that was causing what you were observing.

-enlil

Replies are listed 'Best First'.
Re: Re: Basic question about split
by jweed (Chaplain) on Dec 13, 2003 at 02:12 UTC
    Interestingly enough, in this Apocalypse lwall basically says that length(@array) should be more DWIMmy, and that it more or less will be in perl6.


    Who is Kayser Söze?
    Code is (almost) always untested.