in reply to Re: Nested foreach
in thread Nested foreach

I'm still getting the same problem after I begun using a different variable instead of $line, why does it still refuse to ignore my words?
my @words; my %search; my $first; my $second; my $line; my @ignore = qq(a and the this i me us our ok abc); my $file = "abc.txt"; my $count = "0"; open (FILE, $file) or die "Error $!"; @words = <FILE>; chomp(@words); close FILE; my @search= @words; foreach my $line (@words) { $line =~ tr/A-Z/a-z/; foreach my $ignore (@ignore) { $ignore =~ s/\b$ignore\b//; } } foreach my $line (@words) { # splitting words on a white space but allowing contractions and hyphe +ns while ($line =~ /([[:alpha:]]+(?:'[[:alpha:]]+)?)/g) { if (exists ($search{$1})) { $search{$1}++; } else { $search{$1}=""; $search{$1}++; } } } while (($first,$second)=each(%search)) { print "$first -- $second\n"; }

Replies are listed 'Best First'.
Re: Re: Re: Nested foreach
by Thelonius (Priest) on Apr 25, 2003 at 17:44 UTC
      foreach my $line (@words) { $line =~ tr/A-Z/a-z/; foreach my $ignore (@ignore) { $line =~ s/\b$ignore\b//g; } }
      doesn't change the outcome of the program either :( No words are ignored but you were right, I need the //g :)
        Oh, I didn't notice that at the top, you need to change
        my @ignore = qq(a and the this i me us our ok abc);
        to
        my @ignore = qw(a and the this i me us our ok abc);
        I.e. change qq to qw.