Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^4: Conditional initialization of lexical (my) variables

by LanX (Saint)
on May 10, 2023 at 20:58 UTC ( [id://11152089]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Conditional initialization of lexical (my) variables
in thread Conditional initialization of lexical (my) variables

not the same thing

This my $x if 0 is definitely a bug, because constant folding shouldn't allow a lexical to be declared.

But the OP has a condition which is only checked at run-time, while the declaration happens at compile-time.

This means the new variable will not be overwritten with an init-value if the condition is false.

The deeper issue is that postfix-conditions have no own scope, the problem is non-existent for if ($bool) {my $x = ... }

Not sure if this qualifies as a bug or a weird feature.

But a warning should happen in any case if a declaration happens before a postfix condition, because of the broken symmetry to prefix conditions.

Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11152089]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2025-11-14 06:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (70 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.