Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Announcing Perl-Critic-0.14

by perrin (Chancellor)
on Jan 30, 2006 at 16:12 UTC ( #526474=note: print w/ replies, xml ) Need Help??


in reply to Announcing Perl-Critic-0.14

Can you make it catch this coding mistake?

my $foo = 1 if $bar;
I've been bitten by that before, and never want it to happen again.


Comment on Re: Announcing Perl-Critic-0.14
Download Code
Re^2: Announcing Perl-Critic-0.14
by holli (Monsignor) on Jan 30, 2006 at 16:23 UTC
    Please forgive my ignorance, but what's wrong with it? $foo ends up as 1 when $bar is true and is undefined when $bar is false. Just as I expect it to be. (Active Perl 5.8.7)
    use warnings; use strict; my $t_bar = 1; my $t_foo = 1 if $t_bar; my $f_bar = 0; my $f_foo = 1 if $f_bar; print "true $t_foo false $f_foo"; #->true 1 false #->Use of uninitialized value in concatenation (.) or string ...


    holli, /regexed monk/
      Please forgive my ignorance, but what's wrong with it? $foo ends up as 1 when $bar is true and is undefined when $bar is false. Just as I expect it to be. (Active Perl 5.8.7)
      Wrong. This piece of code is one of the weird things in perl, in this case, something that is sometimes used as a dirty trick, to create a static variable.
      #!/usr/bin/perl -lw print $]; for (1 .. 5) { my $i = 123 if $bar; print ++$i; }
      Result:
      Name "main::bar" used only once: possible typo at test.pl line 4. 5.008003 1 2 3 4 5
        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/
Re^2: Announcing Perl-Critic-0.14
by jthalhammer (Friar) on Mar 01, 2006 at 08:44 UTC
    We just added that. It will be available in version 0.15 which should be released by the end of March. Thanks for the great suggestion.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (17)
As of 2015-07-02 17:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (44 votes), past polls