in reply to Re: Counting instances of words
in thread Counting instances of words

Thanks for your help. Tried this, and $code appears to be empty. I've declared it outside the While loop, but it prints out as null. Should this contain the total substitutions?

Replies are listed 'Best First'.
Re^3: Counting instances of words
by blazar (Canon) on May 25, 2007 at 19:32 UTC
    Thanks for your help. Tried this, and $code appears to be empty. I've declared it outside the While loop, but it prints out as null. Should this contain the total substitutions?

    Well, for one thing I wouldn't regard $code as a particularly good variable name. Then, if you want the total number of substitutions, you must accumulate them:

    $count += s/\band\b/$word/ig;