Hello

I have a question. I want to merge 2 files("re_file.txt and re_mplus1.txt") to 1 file

The re_file.txt is a list of some keys and data..... maybe 3,000 lines.

The re_mplus1.txt file is a list of data and have same key of re_file.txt ...... maybe 1,000,000 lines

What I want to do is add $d3 to %data1 in the last location.

$d3 is the value "$d2 in the re_file1.txt - $d1 in the re_mplus1.txt"

Is there any way to do it?

The format of result must be...

id c7 c8 id2 p10 p12 d2 d3.......id2~d3 are placed 5 times in case ($d3 <= 5 )

If the list ($d3 <= 5 ) is 4 , than print 4 times

I'm not good at English and I hope I clearly explained my problem to you.

Frankly the source in the below is not mine..T.T .I am just modify original source.

#!/usr/bin/perl open(REFILE, 're_file.txt') || die $!; my %data1; while(<REFILE>) { chomp; next unless $_; my($id1, $id2, $p10, $p11, $p12, $d1) = split; $data1{$id1}->{$id2} = [$id2, $p10, $p11, $p12, $d1]; # referenc +e !! } close(REFILE); # open(PRT,">re_file2.txt"); open(DATAFILE,"re_mplus1.txt"); while(<DATAFILE>) { chomp; next unless $_; my($id, $c7, $c8, $d2) = split(/\s+/, $_); foreach $datafile ( keys %{$data1{$id}}) { $d3 = abs($data1{$id}->{$datafile}[4]-$d2); if($d3 <= 5 ) { # print "$id, abs($data1{$id}->{$datafile}[4]-$d2),$d +3\n"; # %myhash1 = [$data1{$id}->{$datafile}[0],$data1{$id}->{ +$datafile}[1],$data1{$id}->{$datafile}[2],$data1{$id}->{$datafile}[3] +,$data1{$id }->{$datafile}[4],$d3]; } } my @arr = sort { abs($a->[4]) <=> abs($b->[4]) } values %{$data1 +{$id}}; print "$id $c7 $c8 "; print join(" ", map { join(' ', @{$_}[0,1,4]) } splice(@arr, 0, +5 ) ) . "\n"; } close(DATAFILE); # close(PRT);

In reply to hash problem by kjsunny

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.