in reply to Hash Tutorial
Short of that I highly recommend the section in Camel II (possibly in Camel III as well?) in chapter 1 on how Perl data structures map to linguistic operations. The linguistic version of a hashlookup is the word "of". This informs us how we name a hash. If the hash gives us the address of the person, we should say $address{$person}. If it is possible to get an address in several ways we might be more verbose and say $address_by_person{$person}. In either case "talk your way" through the problem in English and wherever you say "of" or an equivalent, that is a good sign that you want a hash.
That said, here are some standard uses that I have for them:
and it is easier to remember how to call the function, and easier to add more useful options later.sub my_function { my %opts = @_; # etc
The actual definitions of the special cases are placed elsewhere. Lest this idea just sound weird, you may want to read Why I like functional programming. (It helps to read the *last* function first - scrub_input - and understand what it does. It may also help to check out what pos does.) OK, perhaps you don't want to try that. Yet.if (exists $handler{$case}) { $handler{$case}->(); # Handle the special case }
UPDATE
Forgot a ++ on $is_seen{$case}. I thought it, and
verbalized it in English, but when I went to write the Perl
at last I apparently forgot it at the last moment...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re (tilly) 1: Hash Tutorial
by jreades (Friar) on Jun 22, 2001 at 18:28 UTC |