poegi has asked for the wisdom of the Perl Monks concerning the following question:
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:
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).#!/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);
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Value in the range struggling (once more)
by kcott (Archbishop) on Mar 16, 2012 at 00:04 UTC | |
by jwkrahn (Abbot) on Mar 16, 2012 at 03:20 UTC | |
by kcott (Archbishop) on Mar 16, 2012 at 12:30 UTC | |
|
Re: Value in the range struggling (once more)
by jwkrahn (Abbot) on Mar 15, 2012 at 23:05 UTC | |
|
Re: Value in the range struggling (once more)
by poegi (Initiate) on Mar 16, 2012 at 00:54 UTC |