APM: Matching against an array of patterns

Bill Raty bill_raty at yahoo.com
Mon Jul 14 11:00:44 CDT 2003


Short answer: if you want to pass two arrays to a perl
subroutine you'll need to use subroutine prototyping -or- perl
references.

See perlref and perlsub.

URL for perlref:
http://www.perldoc.com/perl5.8.0/pod/perlref.html

URL for perlsub:
http://www.perldoc.com/perl5.8.0/pod/perlsub.html



-Bill

--- Randall Hennig <randysleek at hotmail.com> wrote:
> 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
> 
> _______________________________________________
> Austin mailing list
> Austin at mail.pm.org
> http://mail.pm.org/mailman/listinfo/austin




More information about the Austin mailing list