3 ms·
"my $foo = 0 if 0" I was stuck on a version of perl at work that could crash if you did that. If the clause was false, it did something like create the interna
by jerf 4y ago
"my $foo = 0 if 0"
I was stuck on a version of perl at work that could crash if you did that. If the clause was false, it did something like create the internal C-level variable for that variable, but never initialized it to anything, resulting in a true crash-the-process segfault if you ever looked at that variable again. That was fun to track down, and resulted in a slow trickle of trying to explain to a new programmer why they shouldn't do that.
I don't think it reads terrible well anyhow. And I don't mean that as a postfix condition argument; I have opinions about that, but I don't mean that argument. I just mean "create this variable conditionally" doesn't really make a lot of sense under Perl's model and while I learned what happened when the clause was false, I never felt like that was really obvious.
- thyrsus 4y agoWhat would motivate such an expression? Was the intent that the variable have value undef in the false case and 0 in the true case?