in reply to Re: Creating Dictionaries
in thread Creating Dictionaries
It won't compile under use strict; ... i think you meant to pattern match against lc $line, and there's no parens in the regex to capture anything ...while (my ($word) = (lc $word) =~ /[a-z]{2,}/g) {
Which can be rewritten as:my %hash; while (my $line = <STDIN>) { foreach my $word ( $line =~ m/\b([a-zA-Z]{2,4})\b/g ) { $hash{lc $word}++; } } print "$_\n" for sort keys %hash;
while (my $line = <STDIN>) { $hash{lc $_}++ for $line =~ m/\b([a-zA-Z]{2,4})\b/g; } #or do { $hash{lc $_}++ for m/\b([a-zA-Z]{2,4})\b/g } for <STDIN>;
while (my $line = <STDIN>) { $hash{lc $_}++ for $line =~ m/([a-zA-Z]{2,})/g; } delete $hash{$_} for grep /(\w)\1{4}/, keys %hash;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Creating Dictionaries
by Perl Mouse (Chaplain) on Dec 16, 2005 at 14:33 UTC |