in reply to count the occurrences of particular word in a file and extract number in ()
how to I count the occurrences of word 'the' in a file?
open my $fh, '<', 'theFile' or die $!; my $count = 0; while( <$fh> ) { ++$count while m[the]g; } print "'the' appeared $count times in 'theFile'";
how to I extract the numeric values in a () sample code:? $extract =~/^\( (\d.+) \)$/
if( $extract =~/^\( (\d.+) \)$/ ) { print "The number was $1"; } else { print "The regex didn't match"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: count the occurrences of particular word in a file and extract number in ()
by NetWallah (Canon) on Mar 20, 2011 at 05:22 UTC | |
by BrowserUk (Patriarch) on Mar 20, 2011 at 05:57 UTC |