[Za-pm] Hashes
Theunis De Klerk
theunis at ixpress.co.za
Thu Jun 5 05:24:30 CDT 2003
Hi Everyone,
I'm a newbie, especially to Perl.So could someone please explain what
hashes are and what they are used for. From what i see they are sort of
like multi demensional arrays . Is that right?
Muchly appreciated!!!
Theunis
On Thu, 2003-06-05 at 09:32, Spike wrote:
> 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
More information about the Za-pm
mailing list