Re: fun with hashes!
"Mr. Shawn H. Corey" <[email protected]> Fri, 23 Nov 2007 13:37:50 -0500
| Newsgroups | gmane.comp.lang.perl.fun |
|---|---|
| Message-ID | <[email protected]> |
Uri Guttman wrote:
> too long has this list been quiet. but i have a fun question. i am
> writing up slides for an all about hashes class. one goal i have is to
> list and explain as many different uses for hashes as reasonably
> possible. i have a short list to start with but i am sure the hive mind
> of fwp can scrape up a bunch more. each one should have a name and not
> overlap too much with any of this list (my initial list should be
> obvious to you).
#!/usr/bin/perl
use strict;
use warnings;
# Unqiueness
{
my @list = qw( a b c x y z a b c );
my %unique = ();
@unique{@list} = @list;
@list = keys %unique;
print "@list\n";
}
# Counts
{
my @list = qw( a b c x y z a b c );
my %counts = ();
$counts{$_} ++ for @list;
print "$_ : $counts{$_}\n" for keys %counts;
}
__END__
--
Just my 0.00000002 million dollars worth,
Shawn
+------------\
| Shangri La \
| 40,000 km /
+------------/