in reply to undefined or zero: looking for an elegant solution

$metricOpenTasks {$relWeek}{$cc}{"nr"} ||= 1;

or, if you want to operate on the copy

($nr = $metricOpenTasks {$relWeek}{$cc}{"nr"}) ||= 1;

Replies are listed 'Best First'.
Re^2: undefined or zero: loking for an elegant solution
by salva (Canon) on Feb 26, 2010 at 12:40 UTC
    $nr = $metricOpenTasks{$relWeek}{$cc}{nr} || 1;
      yes *facepalm* of course ;-)

      The construct with parens is necessary for substitution after assignment, not just for plain conditional assignment.

      ($foo = $bar) =~ s/$pat/$subst/; # operates on $foo