This should get you started:

#! perl -slw use strict; use Inline::Files; use Data::Dump qw[ pp ]; my @templateIds = split ' ', <TEMPLATE>; my %template = map{ my( $id, @vals )= split(); $id => \@vals } <TEMPLA +TE>; #pp \%template; my @missingIds = split ' ', <MISSING>; my %missing = map{ my( $id, @vals )= split(); $id => \@vals } <MISSING +>; #pp \%missing; for my $i ( 0 .. $#templateIds ) { if( $templateIds[ $i ] ne $missingIds[ $i ] ) { splice @missingIds, $i, 0, $templateIds[ $i ]; for my $k ( keys %missing ) { splice @{ $missing{ $k } }, $i, 0, 0; } $missing{ $templateIds[ $i ] } = [ (0) x @{ $template{ $templa +teIds[ $i ] } } ]; } } print "\t", join ' ', @missingIds; print join ' ', $_, @{ $missing{ $_ } } for @missingIds; __TEMPLATE__ rs12272511 rs7107801 rs11027752 rs12421837 rs12272511 1.0 -0.023 -0.511 -0.046 rs7107801 -0.023 1.0 0.040 0.233 rs11027752 0.494 0.514 1.0 0.501 rs12421837 -0.039 -0.040 0.021 1.0 __MISSING__ rs12272511 rs11027752 rs12421837 rs12272511 1.0 .844 .276 rs11027752 .267 1.0 -.980 rs12421837 -.876 .374 1.0

Output:

C:\test>1152731 rs12272511 rs7107801 rs11027752 rs12421837 rs12272511 1.0 0 .844 .276 rs7107801 0 0 0 0 rs11027752 .267 0 1.0 -.980 rs12421837 -.876 0 .374 1.0

Note:I've used Inline::Files to produce a self-contained example; you'd need to open the real files and operate on them for your real work.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: combining multiple matrices with placeholders if row and column values in one matrix do not exist in another by BrowserUk
in thread combining multiple matrices with placeholders if row and column values in one matrix do not exist in another by mulder4786

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.