lonewolf28 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, I'm trying to list all the values from %ENV, where if a key has no value, then it should print 'undefined value'.
my @max; foreach ( keys %ENV){ push @max, length $_; } my @sorted_max = sort { $a <=> $b } @max; my $max_num = pop @sorted_max; while ( my ($key, $value )= each %ENV) { $value = $value // 'undefined value'; printf "\n%-*s: %s", $max_num, $key, $value; }
I'm using defined-or operator to achieve this, but was unsuccessful. Thanks!
|
|---|