Dear All,
I am an amateur in PERL trying to write a script for matching elements of array but there is slight glitch... Please help me.
I have one file consisting of ids... The other file consisting of ids and a sequence of letters associated with those ids.
eg. File A : 1DWK 2RFK 4ERH and so on...
File B: 1DWK
HRSDKKDAHJKLSDLDLLJDGHDFJJE
4ERH
DFSKFHADFSBVHFWIHFWJBFS
2RFK
DADUHRQWERKBNJAIJDLAJDKAKDNAKDJKSADJKAHDJASHRWEUB
I have written a script to match ids in both the files and return the ids with sequence as result:
#! usr/bin/perl
#this script is to match the two files and print the matched content i
+n the two files
$p="FILEA";
open (FILE1,$p);
@array =<FILE1>;
#print "@array";
$p1="FILEB";
open (FILE2,$p1);
@new = <FILE2>;
#print "@new";
foreach $line (@array)
{
chomp $line;
open (OUT,">nrset.txt");
for($i=0;$i<@new;$i++)
{
chomp $new[$i];
# print "$new[$i]\n";
if ($new[$i] =~ /$line/i)
{
$pos = $i;
print "$pos\n";
print OUT "$new[$i]\n$new[$i+1]\n";
# print "$new[$i]\n$new[$i+1]\n";
}
}}
This script just runs creating a nrset.txt file which is empty but doesn't show any matches. While I supposed my File having ids with sequence is too huge, tried to take few checkfiles which gave expected results as my script should do. Help me fellas!
Thnx in adv.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.