Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: (stephen) Hash Tutorial

by stephen (Priest)
on Jun 22, 2001 at 07:11 UTC ( [id://90617]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    %Pet_Food = (
      'dog' => 'dog chow',
    ...
    
    # $pet_type should be 'dog', 'cat', or 'parakeet'
    my $food = $Pet_Food{$pet_type};
    
  2. or download this
    @Pet_Types = ("dog", "cat", "dog", "parakeet", "dog", "cat");
    
    ...
    my @unique_types = sort keys %type_table;
    # @unique_types winds up with 'cat', 'dog', and 'parakeet'
    
  3. or download this
    %Valid_Pets = (
       'dog' => 1,
    ...
    # but might not.. we die if it doesn't
    exists $Valid_Pets{$pet_type}
      or die "I'm sorry, '$pet_type' is not a valid pet\n";
    
  4. or download this
    name=fluffy species=rabbit weight=5 price=10.00
    name=fido species=dog weight=15 price=30.15
    name=gul_ducat species=cat weight=10 price=40.20
    
  5. or download this
    while (<PET_FILE>) {
      my %pet = parse_pet($_);
    ...
      }
      return %params;
    }
    
  6. or download this
    while (<PET_FILE>) {
      my $pet = parse_pet($_);
    ...
      }
      return \%params;
    }
    
  7. or download this
    # Note: Bad code! No krispy kreme!
    if ( $pet_type eq 'dog' ) {
    ...
      print_lemur_page();
    }
    # .. ad nauseum
    
  8. or download this
    %Pet_Pages = (
      dog => \&print_dog_page,
    ...
    my $page_sub = $Pet_Pages{$pet_type}
       or die "Invalid pet type\n";
    &$page_sub();
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://90617]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-03-28 10:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found