Re: Perlcritic complains about assignment within conditional

2009-12-19 Thread Peter Scott
On Fri, 18 Dec 2009 02:39:07 -0500, Steve Bertrand wrote: >> Note that there is or at least used to be also a side effect in perl >> that would cause that warning if there was an assignment "nearby" a >> conditional, even if not where you'd think it ought to be to complain. >> I forget the details

Re: Perlcritic complains about assignment within conditional

2009-12-17 Thread Steve Bertrand
Peter Scott wrote: > Although it turned out not to be what was going on here, just to address > your subject line' it's not just Perlcritic that will complain about > assignment in a conditional, but also warnings: > > % perl -wle 'print 42 if $x = 0' > Found = in conditional, should be == at -e

Re: Perlcritic complains about assignment within conditional

2009-12-17 Thread Peter Scott
Although it turned out not to be what was going on here, just to address your subject line' it's not just Perlcritic that will complain about assignment in a conditional, but also warnings: % perl -wle 'print 42 if $x = 0' Found = in conditional, should be == at -e line 1. And of course you sho

Re: Perlcritic complains about assignment within conditional

2009-12-16 Thread C.DeRykus
On Dec 15, 5:17 pm, shawnhco...@gmail.com (Shawn H Corey) wrote: > Uri Guttman wrote: > >> "SHC" == Shawn H Corey writes: > >   SHC> Try: > >   SHC> my $month = ''; > >   SHC> $month = $ARGV[0] if $ARGV[0]; > > > or just use ||: > > >    my $month = $ARGV[0] || '' ; > > $ cat myscript.pl > #!/

Re: Perlcritic complains about assignment within conditional

2009-12-15 Thread John W. Krahn
Steve Bertrand wrote: John W. Krahn wrote: Steve Bertrand wrote: if ( $month !~ m{ \A \d{4}-\d{2} \z }xms ) { print "\nInvalid date parameter. Must be supplied as '-MM'\n\n"; exit; You exit the program if $month is not equal to a seven character string. ehhh.. *scratching head w

Re: Perlcritic complains about assignment within conditional

2009-12-15 Thread Uri Guttman
> "SB" == Steve Bertrand writes: >> I was just thinking, but didn't get a chance to test what would happen >> if I declared $var = '', and then performed a regex check on it. SB> This tells me that pre-declaring a var with '' makes my original logic fail: that isn't 'predeclaring' bu

Re: Perlcritic complains about assignment within conditional

2009-12-15 Thread Steve Bertrand
Steve Bertrand wrote: > John W. Krahn wrote: >> perldoc perlsyn >> [ SNIP ] >> NOTE: The behaviour of a "my" statement modified with a statement >> modifier conditional or loop construct (e.g. "my $x if ...") is >> undefined. The value of the "my" variable may be "undef", any >> p

Re: Perlcritic complains about assignment within conditional

2009-12-15 Thread Steve Bertrand
John W. Krahn wrote: > Steve Bertrand wrote: >> Hi everyone, > > Hello, > >> I'm reviewing a script I wrote that I use against one of my modules. The >> script takes an optional param at the command line. >> >> Although I am seriously reviewing my options for better and smarter ways >> to utilize

Re: Perlcritic complains about assignment within conditional

2009-12-15 Thread Venkat Saranathan
Steve, You need to declare $month in a separate line. The variable may not exist if the statement evaluate to false. I think that's what it is complaining about. -venkat On 12/15/09, Steve Bertrand wrote: > Hi everyone, > > I'm reviewing a script I wrote that I use against one of my modules.

Re: Perlcritic complains about assignment within conditional

2009-12-15 Thread Jim Gibson
On 12/15/09 Tue Dec 15, 2009 4:49 PM, "Shawn H Corey" scribbled: > Steve Bertrand wrote: >> my $month = $ARGV[0] if $ARGV[0]; > > $ cat myscript.pl > #!/usr/bin/perl > > use strict; > use warnings; > > my $month = $ARGV[0] if $ARGV[0]; > print "$month\n"; > $ ./myscript.pl > Use of uninitial

Re: Perlcritic complains about assignment within conditional

2009-12-15 Thread John W. Krahn
Steve Bertrand wrote: Hi everyone, Hello, I'm reviewing a script I wrote that I use against one of my modules. The script takes an optional param at the command line. Although I am seriously reviewing my options for better and smarter ways to utilize command line args, I'm curious as to why

Re: Perlcritic complains about assignment within conditional

2009-12-15 Thread Steve Bertrand
Steve Bertrand wrote: > Uri Guttman wrote: >>> "SHC" == Shawn H Corey writes: >> SHC> Steve Bertrand wrote: >> >> my $month = $ARGV[0] if $ARGV[0]; >> >> that is similar to the broken my $foo = 1 if 0 used to make static vars >> inside a sub. the assignment won't even happen unless you hav

Re: Perlcritic complains about assignment within conditional

2009-12-15 Thread Shawn H Corey
Uri Guttman wrote: >> "SHC" == Shawn H Corey writes: > SHC> Try: > SHC> my $month = ''; > SHC> $month = $ARGV[0] if $ARGV[0]; > > or just use ||: > > my $month = $ARGV[0] || '' ; $ cat myscript.pl #!/usr/bin/perl use strict; use warnings; my $month = $ARGV[0] || ''; print "mon

Re: Perlcritic complains about assignment within conditional

2009-12-15 Thread Steve Bertrand
Uri Guttman wrote: >> "SHC" == Shawn H Corey writes: > > SHC> Steve Bertrand wrote: > >> my $month = $ARGV[0] if $ARGV[0]; > > that is similar to the broken my $foo = 1 if 0 used to make static vars > inside a sub. the assignment won't even happen unless you have a true value. > > SHC

Re: Perlcritic complains about assignment within conditional

2009-12-15 Thread Uri Guttman
> "SHC" == Shawn H Corey writes: SHC> Steve Bertrand wrote: >> my $month = $ARGV[0] if $ARGV[0]; that is similar to the broken my $foo = 1 if 0 used to make static vars inside a sub. the assignment won't even happen unless you have a true value. SHC> Try: SHC> my $month = ''; SHC>

Re: Perlcritic complains about assignment within conditional

2009-12-15 Thread Steve Bertrand
Shawn H Corey wrote: > Steve Bertrand wrote: >> my $month = $ARGV[0] if $ARGV[0]; > > $ cat myscript.pl > #!/usr/bin/perl > > use strict; > use warnings; > > my $month = $ARGV[0] if $ARGV[0]; > print "$month\n"; > $ ./myscript.pl > Use of uninitialized value $month in concatenation (.) or string

Re: Perlcritic complains about assignment within conditional

2009-12-15 Thread Shawn H Corey
Steve Bertrand wrote: > my $month = $ARGV[0] if $ARGV[0]; $ cat myscript.pl #!/usr/bin/perl use strict; use warnings; my $month = $ARGV[0] if $ARGV[0]; print "$month\n"; $ ./myscript.pl Use of uninitialized value $month in concatenation (.) or string at ./myscript.pl line 7. Try: my $month =

Perlcritic complains about assignment within conditional

2009-12-15 Thread Steve Bertrand
Hi everyone, I'm reviewing a script I wrote that I use against one of my modules. The script takes an optional param at the command line. Although I am seriously reviewing my options for better and smarter ways to utilize command line args, I'm curious as to why perlcritic complains to me, and (i