#!/usr/local/bin/perl # Jaime Prilusky, 2002 # data from http://www.genomesize.com/ # initialize a 'mammals' hash with key-value pairs my %mammals = ( "Ornithorhynchus anatinus" => 54, "Tachyglossus aculeatus" => 64, "Gorilla gorilla" => 48, "Homo sapiens" => 48, "Pan troglodytes" => 48, "Pongo pygmaeus" => 48, ); # print the entire hash, sorted by specie print "\n"; foreach $specie (sort keys %mammals) { my $diploidNumber = $mammals{$specie}; printf ("%30s %d\n",$specie,$diploidNumber); } $mammals{'Ornithorhynchus anatinus'} = undef; # print the entire hash, sorted by specie print "\n"; foreach $specie (sort keys %mammals) { my $diploidNumber = $mammals{$specie}; printf ("%30s %d\n",$specie,$diploidNumber); } # print the entire hash, sorted by specie. Skip undefined values print "\n"; foreach $specie (sort keys %mammals) { next if (!defined $mammals{$specie}); my $diploidNumber = $mammals{$specie}; printf ("%30s %d\n",$specie,$diploidNumber); }