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();