[Za-pm] Hashes

Spike spikeh at mweb.co.za
Thu Jun 5 02:32:37 CDT 2003


At 2003/06/05 08:47 AM, Sean Carte wrote:
>Chapter 4 of the Camel is a good place to start, or end, or go back to
>repeatedly until it suddenly starts to make sense.

Oh yes! I know exactly what you mean. All the books seem to get too deep 
into hashes too quick.

My advice is to just start trying to put something in a hash and get it out 
again - it will make sense eventual - I promise.

In one of the reference books is says something like "There is no technical 
limit to the number of dimensions in a hash array [hashes of hashes of 
hashes ...] But most human programers stop at 3"

Start simple:-

%hash = (
         car  => 1,
         wife => 2,
         dog => 4,
         kids => 2
         )

print "$hash{car}\n";   #  1  expected
print "$hash{wife}\n;   #   2 expected

$hash{dog} = 6;

print "$hash{dog}\n";  #  6 expected

$hash{dog} ++;

print "$hash{dog}\n";  #  7 expected

foreach $key (keys %hash)
{
         print "The value for key $key is $hash{$key}\n";
}

#  The value for key car is 1
#  The value for key wife is 2
#  etc. expected


Remember that keys are unique so you can use a hash as a unique command.







Spike Hodge

UNIX Programmer
M-Web Technology
021 596 8496
082 901 5265

Click here and make M-Web your homepage
http://homepage.mweb.co.za 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/za-pm/attachments/20030605/2a2a2a41/attachment.htm


More information about the Za-pm mailing list