Dear Monks,
I have to parse file 1 using it as a hash key table and then
using key locate the position in file 2. Once I have
located the position of key. Then after locating the
position I have to go backwards searing the word "FAN". Once
I locate the FAN word then I have to move in a window of 3
from the fan word until I reach my position and include it
in the 3 window and then print it to the output.
File 1 looks ilke this:- 12345 11 67890 21 File 2 looks like this:- 12345 ABCDEFANABCDEFGHIJKLMNOPQRSTVVWXWZ 67890 ABACFHAYJAYAFANJAKALAHUSSGSJISUSSKSOWUWSLSS --------------------END----------------
Now I have to do like this :-
Suppose I have found the position 11 of File 1 in File 2
(C). Then I have to search backward to find "FAN". Once
located then I have move by the window of 3 which will
include the position C and output the 3 letters which
include the position (C) => ABC is the output.
I have written a program but it is not giving the correct
output.
Please help
#!/usr/bin/perl -w my %href; my $fn = "key.txt"; open(FH, "$fn") || die "Cannot open file"; while (<FH>) { chomp($_); $href{$1} = $2 if $_ =~ /(\S+)\s+(\S+)/; } while (my ($key, $value) = each(%href)) { #print $key. ", ". $value."\n"; } open(FD,"<check.txt") || die("Can't open: $!"); $/ = '>'; while ( <FD> ) { chomp; next unless ( s{ \A (\S+) \s+ (?= \d ) }{}xms and exists( $href{$1 +} )); my $name = $1; my $position = $2; my @numbers = split /\w+/; my $one_number = $numbers[$href{$name} - 1]; #if ( $one_number >= $quality ) { print "$name\t\t$href{$name}\t$one_number\n"; #print F1 "$name\t\t$href{$name}\t$one_number\n"; # } } close FD; #close F1;

20081224 Janitored by Corion: Restored content


In reply to Regex problem by ashnator

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.