in reply to Re: Optimization of array looping...
in thread Optimization of array looping...

Darn, my brain has gone blank. There must be a better way to specify the slice continues until the end of the array: $parent2[-1] is the last element, but @parent[3..-1] is empty even if @parent2 has more than four elements.
This will DWYM:
@parent[3..@parent-1]
But this is simply the replacement for the deprecated $#array syntax.

Update: removed deprecated.

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re: Re: Re: Optimization of array looping...
by antirice (Priest) on Mar 04, 2004 at 05:17 UTC

    I think you are a bit confused.

    Taking a look at perldoc perlvar, one might note that $# is deprecated. This is not the same $#array of which you speak. Your code above breaks whenever anyone bothers changing $[ (perhaps an insane programmer wishing to update your code?). Your code above should instead be written as:

    @parent[3..@parent-1+$[]

    Of course, @parent - 1 + $[ is a long way of saying $#parent. So why not just use it?

    antirice    
    The first rule of Perl club is - use Perl
    The
    ith rule of Perl club is - follow rule i - 1 for i > 1

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Re: Re: Optimization of array looping...
by jweed (Chaplain) on Mar 04, 2004 at 05:00 UTC
    perldata and perldelta don't seem to mention this deprecation. Is this a bleedperl change?

    Personally, I think the $#array syntax is more manageable than the ugly @array-1 (semantically, this makes little sense) and (heaven forbid!) scalar(@array)-1 (clearer but just as semantically useless.)

    Just by $.02



    Code is (almost) always untested.
    http://www.justicepoetic.net/