in reply to match diagonal text
From the above matrix i need to find diagonal 1111 or 2222.
Do you mean that you are only interested in exactly 4 (not say 3) of '1's or '2's on a diagonal?
Are you only interested in those on this \ diagonal and not this / one?
Will the input always be 6 x 4?
If the answers to those three are yes, then a simple regex may be all you need:
print $_, "\n", m[([12])(?:.{7}\1){3}]s ? 'matched' : 'failed' for $a, $b, $c, $d;; 220021 000200 020222 020222 failed 100000 010000 001000 000100 matched 102000 010200 001020 000102 matched 102000 010200 001020 000201 failed
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: match diagonal text
by arivu198314 (Sexton) on Sep 22, 2011 at 09:11 UTC | |
by BrowserUk (Patriarch) on Sep 22, 2011 at 12:05 UTC | |
by raybies (Chaplain) on Sep 22, 2011 at 12:41 UTC | |
by arivu198314 (Sexton) on Sep 22, 2011 at 12:43 UTC | |
by BrowserUk (Patriarch) on Sep 22, 2011 at 13:21 UTC | |
by arivu198314 (Sexton) on Sep 23, 2011 at 06:25 UTC |