in reply to filling in the zeros...please help

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).

Replies are listed 'Best First'.
Re^2: filling in the zeros...please help
by david_lyon (Sexton) on May 15, 2012 at 22:23 UTC
    Thank you very much Kenosis. This is very useful and helped a lot.