artist has asked for the wisdom of the Perl Monks concerning the following question:
I would like to match whatever matches first among my patterns:
The Output is:#!/usr/local/bin/perl -w use strict; my $str1 = 'ABCBXBCA'; my $str2 = 'APCBXBCAC'; my @patterns = ('B.B', 'CB'); foreach my $string ($str1,$str2){ foreach my $pat (@patterns){ if($string =~ /$pat/){ print "String:$string Pattern:$pat KeyWord:$` +\n";; last; } } }
String:ABCBXBCA Pattern:B.B KeyWord:A String:APCBXBCAC Pattern:B.B KeyWord:APCI would like to have
String:ABCBXBCA Pattern:B.B KeyWord:A String:APCBXBCAC Pattern:B.B KeyWord:APJust note the only change of AP from APC in the current results.. as the pattern 'CB' can match first before 'B.B'.
How I can accomplish this..
Thanks,
Artist
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: First Pattern Matching
by BrowserUk (Patriarch) on Jul 10, 2002 at 22:42 UTC | |
by jryan (Vicar) on Jul 11, 2002 at 22:00 UTC | |
|
Re: Re: First Pattern Matching
by jryan (Vicar) on Jul 10, 2002 at 22:54 UTC | |
by Anonymous Monk on Jul 11, 2002 at 23:23 UTC | |
by jryan (Vicar) on Jul 12, 2002 at 01:19 UTC | |
by Anonymous Monk on Jul 12, 2002 at 02:28 UTC | |
|
Re: First Pattern Matching
by Anonymous Monk on Jul 11, 2002 at 21:31 UTC | |
|
Re: First Pattern Matching
by Aristotle (Chancellor) on Jul 11, 2002 at 22:42 UTC | |
by Anonymous Monk on Jul 11, 2002 at 23:56 UTC |