From abc5ec2c09d1927481acc6612bd9b7b0a20b761b Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Thu, 18 May 2017 14:56:39 +0200 Subject: [PATCH] TT#16370 Fix perlcritic errors Change-Id: Ifdf0034edcfd35d3e5472b0d01e3d3c2726a8d90 --- acc-cleanup.pl | 13 ++++++++----- binlog-purge.pl | 22 ++++++++-------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/acc-cleanup.pl b/acc-cleanup.pl index 160ed42..42c9d4c 100755 --- a/acc-cleanup.pl +++ b/acc-cleanup.pl @@ -6,13 +6,12 @@ use DBI; use Sys::Syslog; openlog("acc-cleanup", "ndelay,pid", "daemon"); -$SIG{__WARN__} = $SIG{__DIE__} = sub { +$SIG{__WARN__} = $SIG{__DIE__} = sub { ## no critic (Variables::RequireLocalizedPunctuationVars) syslog('warning', "@_"); }; my $config_file = "/etc/ngcp-cleanup-tools/acc-cleanup.conf"; #$config_file = "/home/rkrenn/test/acc-cleanup.conf"; -open(CONFIG, "<", $config_file) or die("Program stopping, couldn't open the configuration file '$config_file'.\n"); ######################################################################## @@ -22,7 +21,7 @@ sub delete_loop { my ($table, $mtable, $col, $mstart) = @_; my $limit = ''; - $vars{batch} && $vars{batch} > 0 and $limit = " limit $vars{batch}"; + $vars{batch} and $vars{batch} > 0 and $limit = " limit $vars{batch}"; my $sth = $dbh->prepare("show fields from $table"); $sth->execute; @@ -122,7 +121,7 @@ sub cleanup { my ($table) = @_; my $limit = ''; - $vars{batch} && $vars{batch} > 0 and $limit = " limit $vars{batch}"; + $vars{batch} and $vars{batch} > 0 and $limit = " limit $vars{batch}"; my $col = $vars{"time-column"}; while (1) { @@ -195,7 +194,9 @@ $cmds{cleanup} = sub { cleanup($table); }; -while (my $line = ) { +open my $config_fh, '<', $config_file or die "Program stopping, couldn't open the configuration file '$config_file'.\n"; + +while (my $line = <$config_fh>) { $line =~ s/^\s*//s; $line =~ s/\s*$//s; @@ -218,3 +219,5 @@ while (my $line = ) { $sub->($rest, \@rest); } + +close $config_fh; diff --git a/binlog-purge.pl b/binlog-purge.pl index c94efa0..63a232a 100755 --- a/binlog-purge.pl +++ b/binlog-purge.pl @@ -7,31 +7,25 @@ use DBI; use Sys::Syslog; openlog("binglog-purge", "ndelay,pid", "daemon"); -$SIG{__WARN__} = $SIG{__DIE__} = sub { +$SIG{__WARN__} = $SIG{__DIE__} = sub { ## no critic (Variables::RequireLocalizedPunctuationVars) syslog('warning', "@_"); }; -our $DBUSER; -our $DBPASS; -our $DBREMOTEUSER; -our $DBREMOTEPASS;; - +my %config = map { $_ => undef } qw(dbuser dbpass dbremoteuser dbremotepass); my $config_file = "/etc/ngcp-cleanup-tools/binlog-purge.conf"; -open CONFIG, "$config_file" or die "Program stopping, couldn't open the configuration file '$config_file'.\n"; +open my $config_fh, '<', $config_file or die "Program stopping, couldn't open the configuration file '$config_file'.\n"; -no strict 'refs'; -while () { +while (<$config_fh>) { chomp; # no newline s/#.*//; # no comments s/^\s+//; # no leading white s/\s+$//; # no trailing white next unless length; # anything left? my ($var, $value) = split(/\s*=\s*/, $_, 2); - $$var = $value; + $config{lc $var} = $value; } -use strict 'refs'; -close CONFIG; +close $config_fh; my (undef, $me) = uname(); @@ -45,8 +39,8 @@ elsif ($me eq "sp2") { } -my @creds = ('dbi:mysql:', $DBUSER, $DBPASS); -my @remotecreds = ('dbi:mysql:', $DBREMOTEUSER, $DBREMOTEPASS); +my @creds = ('dbi:mysql:', $config{dbuser}, $config{dbpass}); +my @remotecreds = ('dbi:mysql:', $config{dbremoteuser}, $config{dbremotepass}); my $dbh = DBI->connect(@creds) or die;