- or download this
%Pet_Food = (
'dog' => 'dog chow',
...
# $pet_type should be 'dog', 'cat', or 'parakeet'
my $food = $Pet_Food{$pet_type};
- 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'
- 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";
- 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
- or download this
while (<PET_FILE>) {
my %pet = parse_pet($_);
...
}
return %params;
}
- or download this
while (<PET_FILE>) {
my $pet = parse_pet($_);
...
}
return \%params;
}
- or download this
# Note: Bad code! No krispy kreme!
if ( $pet_type eq 'dog' ) {
...
print_lemur_page();
}
# .. ad nauseum
- or download this
%Pet_Pages = (
dog => \&print_dog_page,
...
my $page_sub = $Pet_Pages{$pet_type}
or die "Invalid pet type\n";
&$page_sub();