ashnator has asked for the wisdom of the Perl Monks concerning the following question:


Hi I have got a bug in my program and I donno howto solve that. I am using the keys in File 1 to parse the file 2. Now the
problem is that when my program comes to the end of string 70th character or around, it does not report the 3 three window
characters as I am doing in the rest of my code. Can somebody help Plz ;)
Here is my code
#!/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; } } my %sequences; { open(my $fh, '<', $qfn2) or die("Cannot open file \"$qfn2\": $!\n"); my $key; while (<$fh>) { if ( s/^>// ) { $key = ( split /\|/ )[1]; } else { chomp; $sequences{$key} .= $_; } } } for my $key ( sort keys %positions ) { if ( ! exists( $sequences{$key} )) { warn "KEY $key in File1 not found in File2\n"; next; } if ( length( $sequences{$key} ) < $positions{$key} ) { warn "KEY $key: File2 string length too short for File1 positi +on value\n"; next; } my $index = rindex( $sequences{$key}, "ATG", $positions{$key} ); if ( $index < 0 ) { warn sprintf( "KEY %s: No ATG in File2 string prior to positio +n %d\n", $key, $positions{$key} ); next; } $index += 3 while ( ($index + 3) < $positions{$key} ); print "$key $positions{$key} " . substr($sequences{$key}, $index, +3) . "\n"; }
My Input file look like this:-
File 1:- 155369268 17 C 169212695 70 C 269212605 90 G File 2:- >gi|155369268|ref|NM_001100917.1| some text AAACAATGTCGATTCTATGATGCGAACGCAGCATTTCAGGGACTGGAATGGGAGCTTACGGTTTTTTACG ACAGAATCATCAATATCTTGGAAGAAAAAGAATGTTAAGAAATAACAAAACAATAATTATTAAGTACTTT >gi|169212695|ref|XM_001716884.1| some text AGACAAGCTTGTCCTGATGTTCCTTGCCCTGGCAGATGTTCAGGACCATGGGAGCTTACGGTTTTTTACG CTAAATGGCCCAAGCTTTCGGGGCTGTCATTGTCTGTTTGTCATTCAAGGGCCCAAGCTGAAGAGGGGGT >gi|269212605|ref|XM_401716884.1| some text AGACAAGCTTGTCCTGATGTTCCTTGCCCTGGCAGATGTTCAGGACCTTCCTTTGATTCAACCCTATGAC CTAATTGGCCCAAGCTTTCGGGGCTGTCATTGTCTGTTTGTCATTCAAGGGCCCAAGCTGAAGAGGGGGT
Output should be like this:-
155369268 7 CTA 169212695 70 CGC 269212605 120 GGG
good bye

20081224 Janitored by Corion: Restored content

Replies are listed 'Best First'.
Re: Unable to catch 70th character in 3 window size
by Corion (Patriarch) on Dec 23, 2008 at 09:23 UTC

    Your program works for me:

    >perl -w 732261.pl 155369268 17 ATG 169212695 70 CGC 269212605 90 GGG

    Maybe you can show us what your program does instead? Also, please try to reduce your program before posting.

      Ah I had some problems on the windows machine.. strange :( I had written in on fedora core 5... well i donno what is the reason but i checked again its working. Maybe my perl version having some problem in windows...