3 # Modify the program from Exercise 3 in Chapter 6 (the environment
4 # lister) to print (undefined value) for environment variables
5 # without a value. You can set the new environment variables in the
6 # program. Ensure that your program reports the right thing for
7 # variables with a false value. If you are using Perl 5.10 or
8 # later, use the // operator. Otherwise, use the conditional
13 #Write a program to list all of the keys and values in %ENV. Print the
14 #results in two columns in ASCIIbetical order. For extra credit, arrange the
15 #output to vertically align both columns. The length function can help you
16 #figure out how wide to make the first column. Once you get the program
17 #running, try setting some new environment variables and ensuring that they
18 #show up in your output.
27 $ENV{"UNDEF"} = undef;
30 foreach my $key (sort(keys %ENV)) {
31 if (length($key) > $maxlen) {
32 $maxlen = length($key);
35 foreach my $key (sort(keys %ENV)) {
36 printf "%${maxlen}s => %s\n", $key, $ENV{$key} // "(undefined value)";