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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Set::Scalar saves you from hash acrobatics
by Jenda (Abbot) on Oct 06, 2003 at 18:25 UTC | |
by zby (Vicar) on Oct 07, 2003 at 09:22 UTC | |
| |
|
Re: Set::Scalar saves you from hash acrobatics
by Not_a_Number (Prior) on Oct 06, 2003 at 19:03 UTC | |
|
Re: Set::Scalar saves you from hash acrobatics
by shotgunefx (Parson) on Oct 06, 2003 at 18:48 UTC | |
by Ovid (Cardinal) on Oct 06, 2003 at 19:00 UTC | |
|
Re: Set::Scalar saves you from hash acrobatics
by kabel (Chaplain) on Oct 07, 2003 at 06:39 UTC |