in reply to How to count the total number of times the word 'the' and 'and' occur in 5 files i selected?
Doing this for multiple files and multiple words is left as an exercise for the reader.#!/usr/local/bin/perl -w use strict; open FILE, "<input.txt" or die "Blerch: $!\n"; local $/=undef; my $text=<FILE>; close FILE; print $text; my @ands = $text =~/\b(and)\b/ig; print scalar @ands; __END__ But now I know that twenty centuries of stony sleep were vexed to nightmare by a rocking cradle. And what rough beast, it's hour come round at last, slouches towards Betlehem to be born? And the world turned around the sun. 2
Have a look at perlre for more information on regular expressions.
CU
Robartes-
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to count the total number of times the word 'the' and 'and' occur in 5 files i selected?
by Aristotle (Chancellor) on Jan 28, 2003 at 12:07 UTC | |
by robartes (Priest) on Jan 28, 2003 at 12:28 UTC | |
by Aristotle (Chancellor) on Jan 28, 2003 at 12:32 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |