in reply to Re: Nested foreach
in thread Nested foreach
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 | |
by esoteric neonate (Novice) on Apr 25, 2003 at 18:16 UTC | |
by Thelonius (Priest) on Apr 25, 2003 at 19:31 UTC | |
by esoteric neonate (Novice) on Apr 25, 2003 at 20:57 UTC |