Hello! I have a pattern matching question using Perl 5.10, Windows 7. Suppose I have a file containing the following block of text:
Hello there TODD I my We Us ourselves OUr I. The file has 10 words, including 7 first-person pronouns (and 3 non-pronouns that I have no interest in). I've scrabbled together the following code: #!/usr/bin/perl use strict; use warnings; my @prnouns1 = qw(I we me us myself ourselves mine ours my our); ... while (my $line = <>) { chomp $line; my @strings = split /\s+/, $line; my @words = grep /\w+/, @strings; my $n_words += scalar(@words); $fst_prsn += scalar (grep {my $comp1 = $_; grep {$_ =~ /\b$comp1\b/ig} @words} @prnouns1); } print "Result: Number of words: $n_words - First: $fst_prsn\n"; The result produced by this code is incorrect: Result: Number of words: 10 - First: 6 It's not counting the second "I" although I've included the /g modifier. Can anyone tell me why? How can I accomplish this? Owen Chavez