in reply to Re: Printing non existing hash values as "missing"
in thread Printing non existing hash values as "missing"

Thanks, however my problem is that I have a code with a lot of lines with:

my $out = sprintf "%.3E", $h{A};

were %h is a hash with nested keys and I would need to add the shortest code to the end of line to print the label MISSING.

Replies are listed 'Best First'.
Re^3: Printing non existing hash values as "missing"
by jeffa (Bishop) on Jun 10, 2015 at 16:20 UTC

    How about:

    my $out = exists $h{$_} ? sprintf "%.3E", $h{$_} : 'MISSING';

    As in:

    my %h = ( A => 1.23435, C => 6.78901, ); for ('A' .. 'C') { my $out = exists $h{$_} ? sprintf "%.3E", $h{$_} : 'MISSING'; warn $out; }

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)