plz help
Stormer
open(FILE, "title.txt");
while (<FILE>) {
if(eof()) { # Not eof().
while($_ =~ m/[\w\W\s]*$in[\w\W\s]*/ig){
$k++;
}
}
print OUT "Total no of times $arr1[$j] occured is : $k \n" ;
print "$arr1[$j] : $k \n" ;
$k=0;
}
}
As a side-bar, I believe that if you substitute the search string with a null string, the returned value is the number of substitutions made.
e.g. $x = ($_ =~ s/$search//ig);
Kaled.
PS
I've not used Perl much, so don't take anything above as definitive.
Declare my $k outside of the loop to ensure that it is not local to the loop as it will be overwritten each time the loop runs as opposed to being incremented.
You should be able to just....
use strict;
my $k;
while(<>)
{
chomp;
if($_ =~ m/[\w\W\s]*$in[\w\W\s]*/ig)
{
$k++;
}
}
print $k;
run from command line as:
perl myscript.pl text.txt
perl -ne 'END { print "Word appeared $t times\n" } @w = /(blahblah)/g; $t += @w' test.txt
If you're still confuzled, check this out:
[perl.com...]
And if you just want to know how many lines a phrase appears in, do this:
grep blahblah test.txt ¦ wc -l
(Assuming you're using a real operating system like linux of course)
And if you have a whole directory structure with tons of html files and you want to spell your misspelling of mispelled correctly, you can do this:
perl -pi -e 's/mispelled/misspelled/gi' `find . -name "*.html"`
Rock and Roll.