in reply to Optimization of array looping...

Why not use slices to obtain and copy a complete subset of parent 1 in one operation and then parent2 in a second operation?

@newArray = ( @parent1[0..$crossover], @parent2[$crossover+1..$#parent2] );

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.

--
TTTATCGGTCGTTATATAGATGTTTGCA

Replies are listed 'Best First'.
Re: Re: Optimization of array looping...
by QM (Parson) on Mar 04, 2004 at 04:11 UTC
    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

      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.
      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/