in reply to Re: How to count the total number of times the word 'the' and 'and' occur in 5 files i selected?
in thread How to count the total number of times the word 'the' and 'and' occur in 5 files i selected?

How about not slurping?
#!/usr/bin/perl -w use strict; my $count = 0; $count += /\band\b/g while <>; print "$count\n";

Makeshifts last the longest.

  • Comment on Re^2: How to count the total number of times the word 'the' and 'and' occur in 5 files i selected?
  • Download Code

Replies are listed 'Best First'.
Re^3: How to count the total number of times the word 'the' and 'and' occur in 5 files i selected?
by robartes (Priest) on Jan 28, 2003 at 12:28 UTC
    Of course :). BTW, your solution does not catch multiple 'and's in one line (you just count the number of lines 'and' occurs in at least once). The best of both our worlds would be:
    #!/usr/bin/perl -w use strict; my $count = 0; $count += () = /\band\b/ig while <>; print "$count\n";
    but you were probably aware of this :-)

    CU
    Robartes-

      Ouch, no, forgot - unfortunately, I'm not on a Perl-enabled computer right now, so I couldn't test it even if I wanted to.

      Makeshifts last the longest.