Re: intro

[email protected] (Nathan Torkington)
Newsgroups perl.trainers
Message-ID <[email protected]>
Peter Scott writes:
> I'm having a hard time with hashes for beginners.
> 
> >Do you use analogies and metaphors,
> 
> Of course...

I draw a two-column table on the whiteboard and say "this is a hash."
I label the left column "keys" and the right column "values".  Then
I show the effects of:

  $hash{Nat} = 26;
  print "$hash{Nat}\n";
  $hash{Nat} = 32;
  print "$hash{Nat}\n";

The keys() and values() functions follow from the illustration.

At some point, of course, the analogy breaks down.  In the case of
hashes, it's the order of the lists returned by keys() and values().

Nat
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.