in reply to Creating a hash with key generated by a sub?
You had a few simple errors. This works:
use Digest::MD5 qw(md5_hex); use strict; use warnings; my $secret = "applepie"; sub get_md5 { md5_hex("$secret" . "$_[0]") }; my @array = qw(foo bar baz); my %md5_hash_broken = (map {&get_md5($_) => $_} @array); my %md5_hash = ( &get_md5('foo') => "foo", &get_md5('bar') => "bar", &get_md5('fubar') => "baz", ); my ($x, $y); while (($x, $y) = each %md5_hash) { print "$x => $y\n"; }
The errors (see my changes):
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Creating a hash with key generated by a sub?
by smullis (Pilgrim) on Nov 12, 2004 at 13:21 UTC | |
by steves (Curate) on Nov 12, 2004 at 13:27 UTC |