What's he doing here? He is building a hash so that later on he can check for stopwords like so:my %stopwords; @stopwords{(qw(a i at be do to or is not no the that they then these them who where why can find on an of and it by))} = 1 x 27;
my @salient_word = grep { not $stopwords{$_} } @word ;
Now, what is wrong with what he did? Well, nothing, but there is a module on CPAN, Set::Scalar that makes this tasks more DWIM instead of DWIS.
Here is how the same coding of stop words would be done using it:
And then we check it like this:use Set::Scalar; $stopwords = Set::Scalar->new; $stopwords->insert( qw(a i at be do to or is not no the that they then these them who where why can find on an of and it by)); @word = split /\s+/, "Oh say can you see by the dawn's early light";
or like thismy @salient_word = grep { not $stopwords->has($_) } @word ;
$word = Set::Scalar->new(@word); my $salient_word = $word - $stopwords; # or this: my $salient_word = $word->difference($stopwords);
$members = Set::Scalar->new(@members); my $not_in = $s - $members; my $in = $s->intersect($members); $s->delete($in->members); $s->insert($not_in->members);
In other words, it is ($a - $b) UNION ($b - $a)$N = ($a - $b); $N->insert($b - $a);
Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality.
In reply to Set::Scalar saves you from hash acrobatics by princepawn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |