#!/usr/bin/perl # Tom Blum # May 2007 # IWA-HWG Homework/ Instructor M. Kowalski #print out contents of the environment hash while( ($key, $value) = each %ENV) { print "$key => $value\n"; } #make a copy of the environment hash %env_copy = %ENV; print "\nCopied.\n"; #change some values in the copy of the environment hash $env_copy{"HOMEDRIVE"}="D:"; $env_copy{"TEMP"}="D:\\temp"; $env_copy{"TMP"}="D:\\temp"; #print out contents of the copy of the environment hash foreach $i (keys %env_copy) { chomp($env_copy{$i}); print "$i: $env_copy{$i}\n"; } #delete $env_copy{"PATH"}; #deletes PATH vriable so can test else if(exists $env_copy{"PATH"}) { print "\nFound PATH\n"; print "The PATH environment variable lets the computer know\n"; print "where to look for executable files, such as those with\n"; print "extensions like .exe, .com, and .bat. When a command \n"; print "is invoked from the command line, the computer looks \n"; print "for the corresponding file in the local directory, as \n"; print "well as the locations indicated by the PATH variable.\n"; } else { print "Did not find PATH\n"; print "Let us add one.\n"; $env_copy{"PATH"}="D:\\temp"; } print "\n\nYour PATH is: $env_copy{'PATH'}\n\n"; #delete some key/value pairs from hash delete $env_copy{"HOMEPATH"}; delete $env_copy{"POOP"}; #see what happens if remove something that doesn't exist delete $env_copy{"PROCESSOR_REVISION"}; print "\nAfter Removing\n\n"; #print out contents of the copy of the environment hash foreach $i (keys %env_copy) { chomp($env_copy{$i}); print "$i: $env_copy{$i}\n"; }