I'm hoping someone has a clever way to do this...

Okay, I have an array of arrays (which can just as easily be an array of strings, just don't split the strings into individual characters) and want to perform substitutions vertically. i.e., given this matrix:
xxxYYxxxYYxxx YY YY 4Y 4X 4Y 4Y YY YY
I'd like to do two things, first of all, change all Y's horizontally between x's into x's themselves, and change all 4's vertically between Y's into Y's themselves. This is the result:
xxxxxxxxxxxxx YY YY YY YX YY YY YY YY
Now, the horizontal match to turn the Y's into x's is easy, just join on the line and do the regex as normal. But what's a nice, clever way to do the vertical match to turn the 4's into Y's? (don't worry about precedence compared to the horizontal match)

I know I can always transpose the matrix, do the now horizontal substitution, and then transpose it back, but that seems like an awful lot of effort. Anyone know a smarter way to do it?

In reply to vertical regex in a matrix? by jimt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.