Blob


1 #!/usr/bin/perl
3 #Write a program to list all of the keys and values in %ENV. Print the
4 #results in two columns in ASCIIbetical order. For extra credit, arrange the
5 #output to vertically align both columns. The length function can help you
6 #figure out how wide to make the first column. Once you get the program
7 #running, try setting some new environment variables and ensuring that they
8 #show up in your output.
10 use warnings;
11 use strict;
12 use utf8;
13 use Data::Dumper;
15 my $maxlen;
16 foreach my $key (sort(keys %ENV)) {
17 if (length($key) > $maxlen) {
18 $maxlen = length($key);
19 }
20 }
21 foreach my $key (sort(keys %ENV)) {
22 printf "%${maxlen}s => %s\n", $key, $ENV{$key};
23 }