in reply to pattern matching compilation errors
i am getting sm compilation errors...
It's always a very good idea to say just what errors you are getting, but I can make a few guesses.
while (<FILE>) { push (@line, $_); my $count++; }
The
my $count++;
statement in the while loop above creates and then increments a lexical variable each time through the loop. The value of this variable will never be other than 1 because it goes out of existence at the end of the loop. That's why Perl complains (I'm guessing) about accessing the $count variable in the subsequent forloop: the variable has never been defined in any current scope.
In the for loop, the if statement
if (($st [4] eq /chr1/) && ($st [10] eq /chr1/)) { ... }
is wrong because the // match operator binds to (ie., matches against) a variable via the =~ binding operator, not the eq operator. Without explicit binding, it binds to the $_ default scalar.
Not errors, but...
The whole while loop can be replaced by
my @line = <FILE>;
and then the number of elements in the array (i.e., the number of lines) will be
my $count = @line;
but this variable is not really needed since the for loop can be better expressed as
for my $l (@line) { do_something_with_line($l); }
Update: As Kenosis has pointed out, it is better practice to use the three-argument form of open:
open my $fh, '<', $filename1 or die "opening '$filename1': $!";
|
|---|