SomeNetworkGuy has asked for the wisdom of the Perl Monks concerning the following question:
I have two strings that are identically formatted and will each pass the same regex. I am interested in how to get the below code working with the '/g' modifier.
It seems to not be starting back at the last position found as the loop continues indefinitely and only gets the first 2 values.$s1 = "45 20 00 00 00 03 00"; $s2 = "40 20 00 00 00 00 00"; while ((@a = $s1 =~ /(\d{2})/g) && (@b = $s2 =~ /(\d{2})/g)){ print "found $a[0] and $b[0] !!!\n"; }
found 45 and 40 !!! found 45 and 40 !!! found 45 and 40 !!! found 45 and 40 !!! found 45 and 40 !!! found 45 and 40 !!! found 45 and 40 !!! found 45 and 40 !!! found 45 and 40 !!! found 45 and 40 !!! found 45 and 40 !!! found 45 and 40 !!! ... continues until i break
Any ideas?
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Two Regex Searches Simultaneously (on One Line)
by GrandFather (Saint) on Oct 24, 2010 at 00:24 UTC | |
|
Re: Two Regex Searches Simultaneously (on One Line)
by CountZero (Bishop) on Oct 24, 2010 at 00:29 UTC | |
|
Re: Two Regex Searches Simultaneously (on One Line)
by TomDLux (Vicar) on Oct 24, 2010 at 14:20 UTC | |
by Monkomatic (Sexton) on Oct 24, 2010 at 14:45 UTC | |
|
Re: Two Regex Searches Simultaneously (on One Line)
by SomeNetworkGuy (Sexton) on Oct 24, 2010 at 00:47 UTC |