Re: intro
[email protected] (Peter Scott)
| Newsgroups | perl.trainers |
|---|---|
| Message-ID | <[email protected]> |
At 02:52 PM 10/29/99 -0600, Nathan Torkington wrote:
>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";
Can I have your students? :-) I do this, I also draw analogies with
databases, talk about how a hash is like an array where you get to pick the
indices, give them a cheat sheet showing the different types of basic
operations on the primitives with examples, do examples on the computer in
front of them... and still when they have an exercise involving traversing
a hash some people sit there starting at the screen and eventually type
something like @hash{$values} = keys @keys ...
--
Peter Scott
Pacific Systems Design Technologies