in reply to Re: Counting text strings
in thread Counting text strings
If you do $count = $_ =~ s/foo/foo/g; $count will have how many replacements happened on that line. Instead of using a temp variable to hold it, I simply += it as we go.. I should probably benchmark it to see how it compares, but its late.while ( <FILE> ) { $count += $_ =~ s/foo/foo/g; print "$count so far\n"; }
|
|---|