Here is the updated code:-use of uninitialized value in exists at sample.pl line 33, <FD> line 6 +. use of initialized value in concatenation (.) or string at line 34 <FD +> line 6 KEY in file 1 not found in file 2
#!/usr/bin/perl use warnings; use strict; my $fh1 = "File1.txt"; my $fh2 = "File2.txt"; open(FH, "$fh1") || die ("Can't open: $!"); my @AoH; while ( <FH> ) { push @AoH, { split /[\s]+/ }; } my %sequences; { open(FD, "$fh2") || die("Cannot open: $!"); my $key; while (<FD>) { if ( s/^>// ) { $key = ( split /\|/ )[1]; } else { chomp; $sequences{$key} .= $_; } } } for my $href ( @AoH ) { for my $role ( sort keys %$href ) { my $key; if ( ! exists $sequences{$key} ) { warn "KEY $key in File1 not found in File2\n"; next; } if ( length( $sequences{$key} ) < $href->{$role} ) { warn "KEY $key: File2 string length too short for File1 positi +on value\n"; next; } my $index = rindex( $sequences{$key}, "TTT", $href->{$role} ); if ( $index < 0 ) { warn sprintf( "KEY %s: No TTT in File2 string prior to positio +n %d\n", $key, $href->{$role} ); next; } $index += 3 while ( ($index + 3) < $href->{$role} ); print "$key $href->{$role} " . substr($sequences{$key}, $index, 3) + . "\n"; } }
In reply to Re^2: howto accomodate multiple values
by aspirado
in thread howto accomodate multiple values
by aspirado
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |