Dear Monks,
I actually want the position in File 1 like suppose 21 of 67890 in this case to be fit in 3 word size window after finding the word FAN and starting the 3 window triplets from
that pattern until it reaches the position 21 and fits this position in 3 window size and prints it out to the output.

I have arrived at this code after some changes but The program is printing the 3 word size only just after the FAN word not talking care of the position in the File 1. Example
in the second case 67890 the position is 21 but the output is printing JAK instead of ALA. That means its printing position just next to FAN always instead of the original
position in File 1.
File 1 looks ilke this:- 12345 14 67890 21 File 2 looks like this:- >gi|12345|ref|OM_2343434|Some text ... ABCDEFANADEFGHIJKLMNOPQRSTVVWXWZ >gi|67890|ref|HM_2338373|Some text ... ABACFHAYJAYAFANJAKALAHUSSGSJISUSSKSOWUWSLSS output should be like this:- 12345 11 FGH 67890 21 ALA Also the File 1 position character should be made bold.
The Code is like this:-
#!/usr/bin/perl use strict; use warnings; my $qfn1 = "File1.txt"; my $qfn2 = "File2.txt"; my %positions; { open(my $fh, '<', $qfn1) or die("Cannot open file \"$qfn1\": $!\n"); while (<$fh>) { my ($key, $pos) = split /\s+/; $positions{$key} = $pos; } } { open(my $fh, '<', $qfn2) or die("Cannot open file \"$qfn2\": $!\n"); for (;;) { defined( my $key = <$fh> ) or last; defined( my $text = <$fh> ) or last; chomp($key); chomp($text); defined( my $pos = $positions{$key} ) or next; $pos = $pos - 1 - 3; $pos >= 0 or next; my ($str) = $text =~ /^.{0,$pos}FAN(.{3})/ or next; print("$key: $str\n"); } }

20081224 Janitored by Corion: Restored content


In reply to Extracting Locations in 3 window size by ashnator
in thread 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.