perl - Returning 2 arrays from subroutine depending on stop list -


this has been moved test case here.

re-done:

i want return arrays (must references) 2 subroutines, regex used conditional statement isn't working i'd hoped. i've tried doing one, figure easier.

to clear, goal have array of matches sorted (@all_matches), , add on array (@all_pronoun_matches) sorted same way added @ end.

this @pronoun_matches subroutine:

my ($line, $verbform, $chapternumber, $sentencenumber, $sentence) = @_; @matches; @pronoun_matches; return unless ($line =~ /(\w+)\((\w+)\-\d+\,\s(\w+)\-\d+\)/); #2nd repeat check      $grammar_relation = $1; $argument1 = $2; $argument2 = $3;  return if (($argument1 =~ /^$argument2/i)||($argument2 =~ /^$argument1/i));      foreach $pronoun (@stoplistnoun)     {     if ((lc $pronoun eq lc $argument1) || (lc $pronoun eq lc $argument2))          {         push (@pronoun_matches, $chapternumber, $sentencenumber, $sentence, $grammar_relation, $argument2, $argument1) if ($argument2 =~ /$verbform/i);         push (@pronoun_matches, $chapternumber, $sentencenumber, $sentence, $grammar_relation, $argument1, $argument2) if ($argument1 =~ /$verbform/i);         }     else         {return}     }  return (\@pronoun_matches); 

the @matches has similar subroutine except this:

foreach $pronoun (@stoplistnoun) #just list of words     {     return if ((lc $pronoun eq lc $argument1) || (lc $pronoun eq lc $argument2));     }      push (@matches, $chapternumber, $sentencenumber, $sentence, $grammar_relation, $argument2, $argument1) if ($argument2 =~ /$verbform/i); ##used 'eq', prevented protective showing     push (@matches, $chapternumber, $sentencenumber, $sentence, $grammar_relation, $argument1, $argument2) if ($argument1 =~ /$verbform/i);      return \@matches; 

this called by:

my $matches; $pronoun_matches; $matches = &dependency_checks($lines[$l], $verbform, $chapternumber, $sentencenumber, $sentence); $pronoun_matches = &pronoun_dependency_checks($lines[$l], $verbform, $chapternumber, $sentencenumber, $sentence); push @all_matches, $matches if ($matches); push @all_pronoun_matches, $pronoun_matches if ($pronoun_matches); 

to send print section after being sorted using hashes, i'd use:

@all_matches = (@all_matches, @all_pronoun_matches); however, @all_pronoun_matches has 0 matches (or being filtered somewhere).

question

why @all_pronoun_matches have uninitialized values in it?? after testing, i've found match never gets passed conditional statement, it's same 1 in @matches subroutine!


originally, had wanted remove pronouns , worked fine, know condition works:

foreach $pronoun (@stoplistnoun)         {         return if ((lc $pronoun eq lc $argument1) || (lc $pronoun eq lc $argument2));         } 

i've tried using if-else in foreach , combining subroutines, matches (including pronouns) went @all_matches despite being called correctly (this method posted here before).

let me know if unclear intent or problem.

@all_matches = @matches, @all_pronoun_matches; 

should be

@all_matches = ( @matches, @all_pronoun_matches ); 

, has lower precedence =

if had warnings enabled, have gotten useless use of variable in void context warning alerting @all_pronoun_matches didn't become part of assignment.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -