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

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.

Replies are listed 'Best First'.
Re^5: Return 2 arrays, sort the same, and concatenate them
by Anonymous Monk on Jul 01, 2011 at 16:39 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 think you want next or last instead of return. Return exits a subroutine, last exits a loop.

Re^5: Return 2 arrays, sort the same, and concatenate them
by Anonymous Monk on Jul 04, 2011 at 08:13 UTC

      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 :)

        WOW! I don't know how to thank you (Let me know if there is a way to repay). This helped me learn so much. Just seeing how you debugged it was educational.

        I found the same problems, but didn't know how to fix them: (1)Never thought of checking the whole array, (2)Never thought of using negated if (or unless) instead I just tried else, and failed, and (3)That do loop is new to me.

        Again, thanks a lot.