in reply to Re^2: Return 2 arrays, sort the same, and concatenate them
in thread Return 2 arrays, sort the same, and concatenate them

Yes, it is helpful that way. More modular.

I am almost positive that the wrong info (or none) is being pushed into @all_pronoun_matches.

I came to this conclusion because after using your methods, I got an output that had @all_matches correct. BUT the info in @all_pronoun_matches was messed:

The heading had the wrong count (didn't sort, just had # of @all_matches), and didn't have $match->[4] and $match[5].

The matches under the heading didn't have anything (just printed "Section")

I still can't say why the push isn't working though. THANKS

Replies are listed 'Best First'.
Re^4: Return 2 arrays, sort the same, and concatenate them
by jonc (Beadle) on Jul 01, 2011 at 15:14 UTC

    Okay, it might be that I am returning in that loop, so the matches aren't being kept! How do I prevent the matches that the condition is true for from getting to @all_matches but reaching @all_pronoun_matches?

    I have tried removing the "return" and putting the @all_matches push statements in else, of the foreach. This didn't work:

    It just sorted as if there were no condition statement to separate them. Like everything went into @all_matches

    For clarity, this is the output I'm looking for:

    2 match(es) in which the subject of move is animals :
    
    Section 1_1: Radially symmetrical animals move slowly or not at all .
    
    Section 1_1: Cnidarians also have epithelial cells with muscle fibers whose contractions enable the animals to move , as well as nerve nets that integrate their body activities .
    
    
    1 match(es) in which the subject of move is cavity :
    
    Section 1_1: Flatworms -LRB- phylum Platyhelminthes -RRB- have no body cavity , lack organs for oxygen transport , have only one entrance to the gut , and move by beating their cilia .
    
    
    2 match(es) in which the subject of move is they :
    
    Section 1_1: Others , the sea butterflies and heteropods , have a modified foot that functions as a swimming organ with which they move through open ocean waters .
    
    Section 1_1: Because fluids are relatively incompressible , they move to another part of the cavity when muscles surrounding them contract .

    Even with another heading: "Here are the pronouns:" before "they" shows up.

      Okay, it might be that I am returning in that loop, so the matches aren't being kept! How do I prevent the matches that the condition is true for from getting to @all_matches but reaching @all_pronoun_matches?

      I think you want next or last instead of return. Return exits a subroutine, last exits a loop.

        Ok, I might as well comment on my changes ie your problem

        empty return, instead of last, in dependency_checks, made @all_pronoun_matches empty

        After that, @all_pronoun_matches wasn't all empty, but still had some empty arrayrefs, which is why I added

        and @$matches); and @$pronoun_matches);
        This should have been a change in dependency_checks to return undef instead of an empty ref, but, well, oh well :)

        Next I took a look at \%counts, \%pronouncounts and noticed %counts also contained \%pronouncounts -- and the same went for \@all_matches, it also contained \@all_pronoun_matches, so I went back and modified sub dependency_checks and added not $foundPronouns

        That got the program 98% there, except there was a missing count number, naturally, since counts no longer contained pronouncounts, so I changed $header, and we're 99% there, the only thing misssing is an extra newline before header :)

        Hopefully it makes sense :)