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"; }
In reply to Re: Re: Nested foreach
by esoteric neonate
in thread Nested foreach
by esoteric neonate
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |