Ratazong has asked for the wisdom of the Perl Monks concerning the following question:
Dear fellow monks
I have the following code getting a value of a hash. If the element is not existing or zero, I want to assign "1" to a variable, otherwise the value contained in the hash. The code below does the trick, but looks very clumsy :-( . Can you please propose a more elegant solution?
Thanks in advance! Rata
$nr = $metricOpenTasks {$relWeek}{$cc}{"nr"}; $nr = 1 if (!defined ($nr) || ($nr == 0));
update: Updated the description - thanks jethro for finding this mismatch!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: undefined or zero: loking for an elegant solution
by jethro (Monsignor) on Feb 26, 2010 at 12:40 UTC | |
|
Re: undefined or zero: looking for an elegant solution
by JavaFan (Canon) on Feb 26, 2010 at 15:51 UTC | |
|
Re: undefined or zero: loking for an elegant solution
by shmem (Chancellor) on Feb 26, 2010 at 12:31 UTC | |
by salva (Canon) on Feb 26, 2010 at 12:40 UTC | |
by shmem (Chancellor) on Feb 26, 2010 at 12:49 UTC | |
|
Re: undefined or zero: looking for an elegant solution
by 7stud (Deacon) on Feb 26, 2010 at 14:16 UTC | |
|
Re: undefined or zero: looking for an elegant solution
by tigre (Acolyte) on Feb 26, 2010 at 22:36 UTC |