#!/usr/bin/perl #-w #use warnings; #use strict; my @keys = keys %ENV; my @values = values %ENV; my $counter=0; foreach (@keys) { $counter++; print "($counter) $_ "; next unless ($_); } print "\n\nEnter \"all\" to display all enviroment variables. Enter name or number of variable to display single variable.\n"; my $input = (); # () case insensitive $input =~ s/\s//gi; # g global, \s whitespace if ($input =~ /(all)/i) # i case insensitive { my $count = @keys; print STDOUT "$count variables to display:\n"; my $counter; my $i=-1; foreach (@keys) { $i++; $counter = $i+1; unless ($values[$i]) { $values[$i] = "Empty value."; } if ($keys[$i]) { print STDOUT "\n$counter $keys[$i]:\n$values[$i]\n"; if ($counter == $count) { print STDOUT "\nAll enviroment variables displayed. :)\n"; } } sleep(1); } } else { if ($input =~ /[0-9]/) { $input = $input-1; print "$values[$input]\n"; } else { $input = uc $input; if ($ENV{"$input"}) { print $ENV{"$input"}; } else { print "Empty value.\n"; } } }