DEV Community

Discussion on: Perl 5.30 deprecates use of my() in a false conditional

Collapse
 
jrw profile image
jrw

I was surprised when I first learned of this. I'm not sure why they didn't just fix the bug, so that

my $foo = "foobar" if $bar;

would be equivalent to

my $foo;
$foo = "foobar" if $bar;

Or, I'm not sure why they didn't fatalize the syntax, regardless of the value of $bar. Today $bar == 1 and your code works; tomorrow $bar == 0 and you get a fatal error?

I'm sure there's lots of code out there using the deprecated syntax.

Collapse
 
mitchjacksontech profile image
Mitch Jackson

This syntax had a bug. The variable did not get garbage collected when it fell out of scope. Perhaps the decision to fatalize it was a practical decision to fix that bug.

Collapse
 
jrw profile image
jrw

Probably it was too hard to just fix it, so fatalizing it was the next best thing? But it seems very risky/buggy to fatalize only in the cases where the conditional expression is false, since that expression is not a constant.