Your code is quite hard to read, partly because you name the variables after the kind of data structure they hold. It is easier to read if you name them according to what they mean.

When I execute your code, I get warnings like this:

splice() offset past end of array at foo.pl line 146. splice() offset past end of array at foo.pl line 147. splice() offset past end of array at foo.pl line 158.
(line numbers may differ from yours a bit).

It basically means that you try to delete an array element that doesn't exist. Which means that at some point the logic that calculates the index $removed is incorrect.

Maybe you could just write a few lines of comment to each function to describe in your own words what it should do, then we can compare that to what it does.

A few suggestions regarding your code:

sub makeArrays { $lower = 10; $upper = 20; my @chroma; my @chromb; my $ranpop; $ranpop = int rand($upper - $lower + 1) + $lower; # @arrA and @arrD hold the same values, and # aren't modified - why do you need them both? # what is their purpose? my @arrA = ( 1 .. $ranpop ); my @arrD = (1 .. $ranpop ); my $limiter = 50; # you can write that shorter: # my @holda = map { int rand($limiter)} 1 .. $randpop; # my @holdb = map { int rand($limiter)} 1 .. $randpop; my @holda; my @holdb; while ($ranpop) { my $genea = int rand ($limiter); push(@holda, $genea); my $geneb = int rand ($limiter); push(@holdb, $geneb); $ranpop--; } # there's no need to copy these arrays # you can return \@holda and \@holdb directly. my @arrB = ( @holda ); my @arrC = ( @holdb ); return \@arrA, \@arrB, \@arrC, \@arrD; }

You tend to create way too many unnecessary variables that do nothing but clutter up your code (and possibly slow it down):

my $childa = $dada; my $childb = $momb; push @chroma, $childa; push @chromb, $childb;
you can write that as
push @chroma, $dada; push @chromb, $momb;

In reply to Re: So close... by moritz
in thread So close... by BioNrd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.