ashnator has asked for the wisdom of the Perl Monks concerning the following question:
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 helpFile 1 looks ilke this:- 12345 11 67890 21 File 2 looks like this:- 12345 ABCDEFANABCDEFGHIJKLMNOPQRSTVVWXWZ 67890 ABACFHAYJAYAFANJAKALAHUSSGSJISUSSKSOWUWSLSS --------------------END----------------
#!/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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex problem
by ikegami (Patriarch) on Dec 20, 2008 at 08:36 UTC | |
| |
|
Re: Regex problem
by ig (Vicar) on Dec 20, 2008 at 16:08 UTC | |
|
Extracting Locations in 3 window size
by ashnator (Sexton) on Dec 20, 2008 at 16:28 UTC | |
by ig (Vicar) on Dec 20, 2008 at 17:18 UTC |