Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

And to prove that what the join utility does (see solution above) is not trivial but also not very complicated, let's try to emulate what it does in a short perl program.

perl -we 'open $_, "<", shift or die for my($D, $Q); my $p = -1e9999; +my $s = -1e9999; my $x; while (my $q = <$Q>) { chomp($q); my $k = (sp +lit " ", $q)[1]; $p <= $k or die "query not sorted"; $p = $k; while ( +$s < $p and defined(my $d = <$D>)) { (my($l), $x) = (split " ", $d)[2 +,0]; $s <= $l or die "db not sorted"; $s = $l; } my $z = $p == $s ? $ +x : "-"; print $q, " ", $z, "\n"; }' file1.db file2.query

The output is this.

1190 31277 A > T 1 0 0 - 1190 31607 C > A 0 3 1 - 1190 31629 C > T 0 2 0 - 1190 31789 A > G 1 2 5 zm1829427 1190 31882 A > C 0 4 0 - 1190 31883 T > A 0 4 0 zm445312 1190 31883 T > C 2 2 5 zm445312 1190 32199 C > T 0 1 1 - 1190 32487 T > C 0 1 1 - 1190 32496 A > G 0 3 0 -

It is an exercise to the reader to add the "Number of HITS" message.


In reply to Re: duplicates getting omitted while comparing values inside foreach. by ambrus
in thread duplicates getting omitted while comparing values inside foreach. by patric

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-18 04:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found