Good evening everyone,

I am very very new to Perl.

My challenge is: Two similar datasets (thousands of rows & 3 columns in each of them):

T2 23 43 T2 45 78 Tn 66 124 T2 34 lit T3 20 mir Tn 100 net2 Tk 1234 low3

I want to: Find #2dataset elements that are in #1dataset range.

How the workflow should go (in my opinion):Element (LetterNumber or LetterLetter) from the first column of #2dataset matches Element from the first column of #1dataset => Element's Number from the second column of #2dataset is compared to equivalent Element's Ranges (second & third column) of #1dataset => If Number (#2dataset second column) is in any Range => Code from the third column of #2dataset is printed

What I was able to create by myself:

#!/usr/bin/perl use strict; use warnings; use File::Spec; if (scalar(@ARGV) != 2) { print "Usage: perl $0 <range.txt> <code.txt>\n"; exit -1; } my @field; my @fieldd; my @start; my @end; my @numb; my $start; my $end; my $numb; my $fieldd; my $field; my @code; my $code; open(RAN, $ARGV[0]); open(COD, $ARGV[1]); while (<RAN>) { my @field=split(/\t/, $_); push(@eleR, $field[0]); push(@start, $field[1]); push(@end, $field[2]); while (<COD>) { my @fieldd=split(/\t/, $_); push(@eleC, $fieldd[0]); push(@numb, $fieldd[1]); push(@code, $fieldd[2]); foreach $eleC (@eleC) { if (grep (/$eleC/, @eleR)) { foreach $numb (@numb) { if ((@start <= $numb) && ($numb <= @en +d)) {print "$code\n"}}}}} close(RAN); close(COD);
NB: I know this was covered times -> I tried to assemble something by myself and this is the best I could. There is no result & it's incorrect, but I might be going into the right direction. I can't install any new CPAN or something (do not have root permission). There is definitely too much junk in my code, but I am afraid to delete something (it might be necessary).

I hope that someone could help me with this. I've started Perl from scratch on Monday & it's almost Friday. Can't stand such "no result wasted week".

Looking forward


In reply to Value in the range struggling (once more) by poegi

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.