A hash consists of key, value pairs. Only keys can be tested for whether or not they exist, as shown in this snippet:
use Data::Dumper; my %WORD = ('AALIYAH', 'AARON', 'ABBE' , 'ABBEY', 'ABBI', 'ABBIE', 'ABBIGAIL', 'A +LEX'); print Dumper(\%WORD); __DATA__ $VAR1 = { 'ABBI' => 'ABBIE', 'ABBIGAIL' => 'ALEX', 'AALIYAH' => 'AARON', 'ABBE' => 'ABBEY' };
You should be using a hash slice instead.
my @names = ('AALIYAH', 'AARON', 'ABBE' , 'ABBEY', 'ABBI', 'ABBIE', 'A +BBIGAIL', 'ALEX'); my %WORD; @WORD{@names} = (); ...
Take a look at perldoc perldata for more information on the wonderful data structures in perl as well as some nifty tricks that can be performed upon them.
Hope this helps.
antirice
The first rule of Perl club is - use Perl
The ith rule of Perl club is - follow rule i - 1 for i > 1
In reply to Re: Exists in HASH issue
by antirice
in thread Exists in HASH issue
by wsee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |