[EMAIL PROTECTED] wrote:

> Gurus-
> 
> I'm trying to help a co-worker on reg exp/pattern match issue.
> 
> we have a set of items to go through and another set of input that's 
> tested against the first.
> 
> we need to check that items in the second set are a one-for-one match or 
> subset of the latter.
> 
> 
> ie:
> 
> $var1 =~ /$var2/
> 
> where this returns true in a case such as $var1=Jose, Joseph, and Josh and 
> $var2 will be James and Joseph
> 
> when $var2 is James they need to return false and when it is Joseph both 
> Jose and Joseph should return true while Josh returns false.
> 
> So far we haven't found a solution in orielly and trying
> 
> if( $var1 =~ m/$var2/) { print "$var2 contains $var1\n"; }
> else { print "failure on $var2 and $var1\n"; }

I would just shorten var2 to the length of var1:

for my $var1 (qw(Jose Joseph Josh)) {
        for (qw(James Joseph)) {
                my $var2 = substr $_, 0, length $var1;
                my $res = $var1 =~ /$var2/;
                print "res=", $res || '0', " for $var1 =~ /$var2/\n";
        }
}
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to