in reply to Printing non existing hash values as "missing"

$out = sprintf exists$h{B} ? "%.3E" : '%s' , $h{B} || $missing;

although there's not much point in using sprintf in that way.

Replies are listed 'Best First'.
Re^2: Printing non existing hash values as "missing"
by Anonymous Monk on Jun 10, 2015 at 12:15 UTC

    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.

      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)