Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^4: Announcing Perl-Critic-0.14

by holli (Monsignor)
on Jan 30, 2006 at 17:26 UTC ( #526496=note: print w/replies, xml ) Need Help??

in reply to Re^3: Announcing Perl-Critic-0.14
in thread Announcing Perl-Critic-0.14

Conclusion: Always assign something in a my declaration?

The following works as expected.
my $i = $bar ? 123 : undef;
And yeah, that's really weird.

holli, /regexed monk/

Replies are listed 'Best First'.
Re^5: Announcing Perl-Critic-0.14
by Aristotle (Chancellor) on Jan 30, 2006 at 17:59 UTC

    Conclusion: Always assign something in a my declaration?

    More precisely: make sure an assignment with a my on the left-hand side is never conditional.

    Makeshifts last the longest.

      It's not about the assignment. It's that my() should never be conditional. my $foo if $bar is just as bad for the same reason. You're just not likely to write that because it looks funny. my $foo ... for ... is probably also just as bad. The statement modifier form allows the my() to declare the variable for use by all following statements in that scope.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Re^5: Announcing Perl-Critic-0.14
by ysth (Canon) on Jan 30, 2006 at 18:43 UTC
    Always assign something in a my declaration?
    I think it boils down to: Never modify a lexical unless the my() was executed during the current execution of the enclosing block.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://526496]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2018-06-20 10:46 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.