Hi Perlmonks,
Below is a code i'm testing. I am a beginner at Perl and saw that the $` special variable refers to the string preceding a match. I wanted to try using it to print a line previous to a matched string.
If this is not possible then any advice on how to print a string previous to a matched string would be very welcome. The problem is I get the following warning and can't figure out how to fix it
Use of uninitialized value in pattern match (m//) at test.pl line 9, <FH> line 1.
Use of uninitialized value in pattern match (m//) at test.pl line 9, <FH> line 2.
Use of uninitialized value in pattern match (m//) at test.pl line 9, <FH> line 3.
Use of uninitialized value in pattern match (m//) at test.pl line 9, <FH> line 4.
Use of uninitialized value in pattern match (m//) at test.pl line 9, <FH> line 5.
the contents of the file are (i'm only using this file to test the script, normally these files could have several strings of letters with each having a title line beginning with >)
>random_seq
atggtccgtgatcagcatcctttggggaatccacatttattcggaccacctccggattcgtcagcatgac
+agctggtcgugguuuaguaugatgtgatgcgatcatgtacatcaggatttaggaggccctccactgcat
+cgtcgactagacgatcagttagggaaaacgtaugguugugatggtacatgacggaccacacgccgactt
+agcatttgttacagtagcgtgattgacatguuguuggug
I want to test the string of letters for a motif and if found print the line beginning with '>' (i.e. the line/string before the match). finally, here's the code
<code> #!usr/bin/perl
use strict;use warnings;
my $filename = $ARGV[0];
open (FH, $filename) || die "Cannot open file\n";
while (<FH>)
{
if (my $line =~ m/
A-Za-z/)
{
print $`;
}
}
close FH;
<code>
would appreciate any help you have to offer
GrandFather added code tags to break long line.