Hello everyone!, Im new to perl and programming in general (a week!) as this question shows. I have bam files and I want to see how often strings are repeated. However, Im trying to get it to work on a txt file firstly. The thing is, I don't really want to do it as shown below. Is there a way I can code it so I dont have to specify that which I want counted? So it just tells me the frequency of every string in the tab-delimited file? And printing to another text file is preferable to STDOUT.
#!/usr/bin/perl -w print "Enter the name of your file, ie myfile.txt:\n"; my $val = <STDIN>; chomp ($val); my $cnt=0; open (HNDL, "$val") || die "wrong filename"; while ($val = <HNDL>) { while ($val =~ /\bchr1\b/ig) { ++$cnt; } } print "Number of instances of 'chr1' found: $cnt\n\n";
Thank's for your time!
In reply to Counting frequency of strings in files by Cian
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |