$foo = $bar unless $foo;
My solution was something like:
$foo ||= $bar || "Catch";
I tried explaining this by using both
$result = open(FOO,"<..") || "Oops";
and
$a = $a + 1; versus $a += $1;
It slowly sunk in. The unless bit reminded me of a section in the Perl Best Practices book I'm reading. Thanks Damian! I pointed out some extra funny bits by bringing in the C-style short hand for if-then-else. Maybe I was doing this to get a 5 minute break from work..
Is that production code? (Score:1)
''
0
'0'
reference to an empty hash, array, or any of the above
for $foo and $bar are invalid and assigning over them is safe
Re:Is that production code? (Score:1)
Re:Is that production code? (Score:2)
Why should any of those be valid apart from 0.
If you can't see the type and usage of a variable, the solution is to name it correctly.
It should also be clear if 0 is acceptable or not in the code, that would be the only comment possibly needed.
@JAPH = qw(Hacker Perl Another Just);
print reverse @JAPH;