Dear Monks. I'm stuck with a problem and I tried all the possibilities I had in mind. Now I hope someone can give me a hands. Basically my problem is: I have a tab delimited text file 1 with 5 different fields. From this file I need the field five associated to the field 1. Now I have a tab delimited text file 2. Here I have 15 fields and I want to add the info of field 5 from file 1, if the field 11 (of file 2) is equal to the field 1 of file 1. More I just want to add the infos, not to obtain a new file with only the lines with all the info in it. What I have done is to obtain an hash from file 1. Then when going to file 2 I compare the field 11 with all the keys of the hash and if I find the correspondence I print on a new file the line together with the value of the hash. In this way I get only a new out file with only the lines where I have added the new field, but still I want all of them Anyone has any idea about what I'm doing wrong? Guess my problem comes with this code, where I could put an else and print the line $_, but this is printed for all the keys I have in the hash.....too many!
elsif ($rsfound =~ m/^rs[0-9]/i) {foreach my$key (keys(%out)) { if ( $rsfound eq $key ) {print OUTFILE "$_\t $out{$key}\n";} }
Hope you can help me out a bit! Cheers

In reply to Add data to input files by micky744monk

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.