Thank you again for the time you are spending with me....I understood the other problems, whilst the push @array is not really a problem since even with this code printing the @output list I have all the rs from file 1. The code is still not working, but trying to run the code and checking the output I noticed that the first code had an empty hash. Now I tried to play a bit with hash definition (and what I did could be completely wrong) but now the array is giving me the file1 together with a number that could be the position, so I guess the code is treating the file like only one string....I do not know it should be something wrong on the first block and on the hash definition....if you could point me in the right direction, I could keep going on the debugging....
#!/usr/bin/perl -w
use strict;
my$line;
my@fields;
my@output;
my$position;
my%rs;
open (FILE1, 'snp.txt') or die "can't open the file: $!";
open (FILE2,'chr22.txt') or die "can't open the file: $!";
open (FD, '>test.txt') or die "can't open the file: $!";
while ($line=<FILE2>) {
$line=~/^(rs\d{5,})\b/;
$position = tell( FILE2 );
if (defined $line) {
$rs{$line}= $position;
}
}
print %rs;
while (defined ($line= <FILE1>)) {
my@fields= split (/\s+/ ,$line);
@output=grep /^rs\d{5,}\b/ ,@fields;
}
foreach (@output) {
if (exists $rs{$_}) {
seek(FILE2,$rs{$_},0);
my $line= <FILE2>;
print FD $line;
}
}
close FILE1;
close FILE2;
close FD;
The output file is empty to be precise
Cheers again!
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.