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 (in this specific case) how it should have been done differently. Without getting into the different ways to accept and process command line args, will someone point out how _this_ script should have been written to avoid the critic message? Is leaving off the condition the same as having it there? I've left what perlcritic yelled about, and the script in it's entirety. The offending line is marked: acct-dev: ISP-RADIUS % perlcritic src/utilities/aggregate_monthly Variable declared in conditional statement at line 21, column 1. Declare variables outside of the condition. (Severity: 5) #!/usr/bin/perl # - aggregate_monthly # - utility script for ISP::RADIUS # - aggregates totals from aggregate_daily db table into # the aggregate_monthly db table # - same license as module itself # If a month is passed in as the first parameter in the format # YYYY-MM, we will operate on that month. Otherwise, the month # that was existent yesterday will be used. use strict; use warnings; use DateTime; use ISP::RADIUS; my $radius = ISP::RADIUS->new(); # issue is down ---vvvvvvvvvvv my $month = $ARGV[0] if $ARGV[0]; if ( $month !~ m{ \A \d{4}-\d{2} \z }xms ) { print "\nInvalid date parameter. Must be supplied as 'YYYY-MM'\n\n"; exit; } if ( $month ) { $radius->aggregate_monthly( { month => $month } ); } else { $radius->aggregate_monthly(); } ~ -- VISUAL -- 33 1,1 All -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/