#!perl -w use strict; # test ideas in chapter 1 my @numbers = (10,20,30,40,50); my @some = @numbers[1..3,0,4]; print join(" ",@some), "\n"; while ( my $filename = shift @ARGV ) { if ( open( FILE, "< $filename" ) ) { while ( my $line = <FILE> ) { print $line; } close FILE; } else { warn("Unable to open file $filename: $!\n"); } } my %AminoAcids = ( Cys => "Cysteine", Asp => "Aspartic Acid", Glu => "Glutamic Acid"); my @AA = values %AminoAcids; print "Values: ", join(", ", @AA), "\n"; # print in Amino Acids in lexical (alphabetical order) my @lexical_order = sort keys %AminoAcids; while ( my $key = shift @lexical_order ) { print "$key = $AminoAcids{$key}\n"; } # print in Amino Acids in value order my @value_order = sort { $AminoAcids{$a} cmp $AminoAcids{$b} } keys %AminoAcids; while ( my $key = shift @value_order ) { print "$key = $AminoAcids{$key}\n"; } my %check = ( Undefined => undef, Zero => 0, Empty => "", One => 1, String => "anything" ); foreach my $key (sort keys %check) { no warnings; print "Key check: $key\tvalue:->$check{$key}<-\n"; if ( exists $check{$key} ) { print "\tExists, "; } else { print "\tDoes not exist, "; } if ( defined $check{$key} ) { print "Defined, "; } else { print "Is not defined, "; } if ( $check{$key} ) { print "True\n"; } else { print "Is not true\n"; } } print "Home directory: ", $ENV{'HOMEPATH'}, "\n";