Pratyusha Reddy has asked for the wisdom of the Perl Monks concerning the following question:
This is code that i had written to find the occurance of a word eg:ACGT from a file but in the output $count returning '0' only. where is the mistake in the code and why is it returning '0' in the output.
#!/usr/bin/perl -w print "Please type the filename of the Chromosome: "; $chromosomefilename = <STDIN>; chomp $chromosomefilename; unless ( open(CHROMOSOMEFILE, $chromosomefilename) ) { print "Cannot open file \"$chromosomefilename\"\n\n"; exit; } @chromosome = <CHROMOSOMEFILE>; close CHROMOSOMEFILE; $chromosome = join( '', @chromosome); $chromosome =~ s/\s//g; do { print "Enter the Recognition Sequence to search for: "; $recognitionsequence = <STDIN>; chomp $recognitionsequence; my @words = qw ($chromosomefilename); my $count = grep /$recognitionsequence/, @words; print "\$count = $count\n"; } until ( $recognitionsequence =~ /^\s*$/ ); exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Count the occurance of a words in a string
by moritz (Cardinal) on Feb 21, 2012 at 11:23 UTC | |
|
Re: Count the occurance of a words in a string
by JavaFan (Canon) on Feb 21, 2012 at 11:26 UTC | |
|
Re: Count the occurance of a words in a string
by CountZero (Bishop) on Feb 21, 2012 at 21:44 UTC |