APM: Matching against an array of patterns

Randall Hennig randysleek at hotmail.com
Mon Jul 14 10:33:40 CDT 2003


Hey,

I'm still a bit new to Perl, so bear with me plesae :)

I'm trying to match an array of candidates against an array of patterns, but 
I'm having some trouble doing that.  Basically, I think my problem is in 
declaring the array of patterns.  Here is the function I am using:


sub findMatches
{
   my @candidates = $_[0] ;
   my @patterns =  $_[1] ;
   my @results = ();
   foreach my $candidate (@candidates)
   {
      if( scalar( map { $candidate =~ /$_/ ? $_ : () } @patterns ) > 0 )
      {
         push(@results, $candidate);
      }
   }
   return(@results);
}

Here is the array I'm declaring:

my @g_basicTagPatterns =  qw(author objective target title grade filename 
notes
                           art passage questions q\d+ question hint 
explanation
                           distracters correct\sanswers);
my @g_tagPatterns=map {qr/^$_:{0,1}$/i} @g_basicTagPatterns;

Here's the code I'm using, which fails to match:

my $text = "q1";
my @c = ();
push(@c, $text);
print "# matches = " . scalar(&findMatches(@c, at g_tagPatterns)) . "\n";

Any help would be appreciated, thanks :)

Randy

_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*  
http://join.msn.com/?page=features/junkmail




More information about the Austin mailing list