Cian has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Counting frequency of strings in files
by toolic (Bishop) on Apr 23, 2012 at 17:17 UTC | |
|
Re: Counting frequency of strings in files
by GrandFather (Saint) on Apr 24, 2012 at 05:27 UTC | |
by Cian (Initiate) on Apr 25, 2012 at 14:49 UTC | |
|
Re: Counting frequency of strings in files
by 2teez (Vicar) on Apr 23, 2012 at 22:06 UTC | |
|
Re: Counting frequency of strings in files
by Anonymous Monk on Apr 23, 2012 at 17:28 UTC | |
by Cian (Initiate) on Apr 23, 2012 at 18:03 UTC | |
by Anonymous Monk on Apr 23, 2012 at 21:36 UTC |