in reply to Re: Counting the frequency of words in a string
in thread Counting the frequency of words in a string

how about:

use Regexp::List, put the generated regex into $word_regex

my $count = ($count = $text) =~ s/$word_regex//g;

horrible?

  • Comment on Re: Counting the frequency of words in a string

Replies are listed 'Best First'.
Re^2: Counting the frequency of words in a string
by cez (Novice) on Dec 02, 2004 at 22:19 UTC
    oh, i guess that could be just

    my $count = $text =~ s/$word_regex//g;

    (since destroying $text doesn't matter in my case)

      Or
      my $count = () = $text =~ /$word_regex/g;
      The parens make it list context, then you take the scalar context from that.