#!/usr/bin/perl #! To operate, be sure to add user execute permissions to file #! For Windows, you may need to change the path settings to #! include the per compiler. #! Poem extracts is "To the Evening Star" by Bill Blake #! Making a hash. Format is [key] => [value]. %EveningStar = ( "Opening_Line" => "Thou fair-hair'd angel of the evening", "Second_Line" => "Now, whilst the sun rests on the mountains, light", "Line3" => "Thy bright torch of love; thy radiant crown", "Line4" => "Put on, and smile upon our evening bed!", "Author" => "-William_Blake", ); print $EveningStar{Opening_Line}; print "\n"; print "\n"; #! Looping through all the values of a hash (Note Perl doesn'r guarantee line order: while ( ($key, $value) = each %EveningStar ) { print "$value\n"; }; print "\n"; print "\n"; #! Checking if a key exists, using the exist function: if (exists $EveningStar{"Author"}) { print $EveningStar{Author} }; print "\n"; print "\n"; #!Another array, from the book "Learning Perl"; $books{"Fred"} = 3; $books{"wilma"} = 1; $books{"barney"} = 0; $books{"pebbles"} = undef; while ( ($key, $value) = each %books){ if ($value > 0) { print "$key has at least $value books checked out.\n"; } }