Thank you, David, for posting the transformation rules; that helped. jaredor provided an excellent solution for you. Here's an option that uses a rules-embedded s///eg on the two columns as strings:

use Modern::Perl; my ( @table, $id1, $id2, $i ); push @table, [ (split) ] while <DATA>; do { $id1 .= $_->[2]; $id2 .= $_->[3] } for @table; $id1 =~ s/(?<=(.))(0+)(?=(.))/$1==$3?$1 x length $2:$2/eg; $id2 =~ s/(?<=(.))(0+)(?=(.))/$1==$3?$1 x length $2:$2/eg; $i = 0; say "$_->[0]\t$_->[1]\t" . substr( $id1, $i, 1 ) . "\t" . substr( $id2, $i++, 1 ) for @table; __DATA__ 1 100 1 2 101 200 1 2 201 300 1 0 301 400 1 0 401 500 0 2 501 600 0 2 601 700 0 0 701 800 1 1 801 900 1 2

Output:

1 100 1 2 101 200 1 2 201 300 1 2 301 400 1 2 401 500 1 2 501 600 1 2 601 700 1 0 701 800 1 1 801 900 1 2

This solution uses capture results, from within positive look-ahead and positive look-behind assertions, to check the two zero-enclosing digits for sameness by executing a ternary statement whose result is substituted for the enclosed zero(s).


In reply to Re: filling in the zeros...please help by Kenosis
in thread filling in the zeros...please help by david_lyon

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.