From 4572e2d58812a9c5f422a8c2e2401c441d528bb7 Mon Sep 17 00:00:00 2001 From: Hilko Bengen Date: Wed, 30 Mar 2011 20:39:45 +0200 Subject: [PATCH] Use open in a modern way. Two perlcritic warnings triggered this change: - Two-argument "open" used - Bareword file handle opened This should not cause any behavioral changes. --- bin/wanna-build | 36 ++++++++++++++++++------------------ bin/wanna-build-statistics | 6 +++--- bin/wb-graph | 6 +++--- lib/WB/QD.pm | 6 +++--- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/bin/wanna-build b/bin/wanna-build index 27fb212..5ebd619 100755 --- a/bin/wanna-build +++ b/bin/wanna-build @@ -2262,11 +2262,11 @@ sub read_db { my $file = shift; print "Reading ASCII database from $file..." if $verbose >= 1; - open( F, "<$file" ) or + open( my $fh, '<', $file ) or die "Can't open database $file: $!\n"; local($/) = ""; # read in paragraph mode - while( ) { + while( <$fh> ) { my( %thispkg, $name ); s/[\s\n]+$//; s/\n[ \t]+/\376\377/g; # fix continuation lines @@ -2294,7 +2294,7 @@ sub read_db { or die $dbh->errstr; } } - close( F ); + close( $fh ); print "done\n" if $verbose >= 1; } @@ -2334,7 +2334,7 @@ sub export_db { my($name,$pkg,$key); print "Writing ASCII database to $file..." if $verbose >= 1; - open( F, ">$file" ) or + open( my $fh, '>', $file ) or die "Can't open export $file: $!\n"; my $db = get_all_source_info(); @@ -2347,11 +2347,11 @@ sub export_db { $val =~ s/\n*$//; $val =~ s/^/ /mg; $val =~ s/^ +$/ ./mg; - print F "$key: $val\n"; + print $fh "$key: $val\n"; } - print F "\n"; + print $fh "\n"; } - close( F ); + close( $fh ); print "done\n" if $verbose >= 1; } @@ -2428,13 +2428,13 @@ sub send_mail { $to .= '@' . $domain if $to !~ /\@/; $text =~ s/^\.$/../mg; local $SIG{'PIPE'} = 'IGNORE'; - open( PIPE, "| $conf::mailprog -oem $to" ) + open( my $pipe, '|-', "$conf::mailprog -oem $to" ) or die "Can't open pipe to $conf::mailprog: $!\n"; chomp $text; - print PIPE "From: $from\n"; - print PIPE "Subject: $subject\n\n"; - print PIPE "$text\n"; - close( PIPE ); + print $pipe "From: $from\n"; + print $pipe "Subject: $subject\n\n"; + print $pipe "$text\n"; + close( $pipe ); } # for parsing input to dep-wait @@ -2508,8 +2508,8 @@ sub wb_edos_builddebcheck { my $packagearch=""; foreach my $packagefile (@$packagefiles) { - open(P,$packagefile); - while (

) { + open(my $fh,'<', $packagefile); + while (<$fh>) { next unless /^Architecture/; next if /^Architecture:\s*all/; /Architecture:\s*([^\s]*)/; @@ -2519,7 +2519,7 @@ sub wb_edos_builddebcheck { return "Package file contains different architectures: $packagearch, $1"; } } - close P; + close $fh; } if ( $architecture eq "" ) { @@ -2537,14 +2537,14 @@ sub wb_edos_builddebcheck { } print "calling: edos-debcheck $edosoptions < $sourcesfile ".join('', map {" '-base FILE' ".$_ } @$packagefiles)."\n"; - open(RESULT, '-|', + open(my $result_cmd, '-|', "edos-debcheck $edosoptions < $sourcesfile ".join('', map {" '-base FILE' ".$_ } @$packagefiles)); my $explanation=""; my $result={}; my $binpkg=""; - while () { + while (<$result_cmd>) { # source---pulseaudio (= 0.9.15-4.1~bpo50+1): FAILED # source---pulseaudio (= 0.9.15-4.1~bpo50+1) depends on missing: # - libltdl-dev (>= 2.2.6a-2) @@ -2573,7 +2573,7 @@ sub wb_edos_builddebcheck { } } - close RESULT; + close $result_cmd; $result->{$binpkg} = $explanation if $binpkg; return $result; diff --git a/bin/wanna-build-statistics b/bin/wanna-build-statistics index 3d7b0d1..6719306 100755 --- a/bin/wanna-build-statistics +++ b/bin/wanna-build-statistics @@ -69,9 +69,9 @@ while( @ARGV && $ARGV[0] =~ /^-/ ) { } my($lastmsg, %n_state, $total, %n_builder); -open( PIPE, "wanna-build --database=$database --dist=$dist --list=all 2>&1 |" ) +open( my $pipe, '-|', "wanna-build --database=$database --dist=$dist --list=all 2>&1" ) or die "Cannot spawn wanna-build: $!\n"; -while( ) { +while( <$pipe> ) { if (/^Database for $dist doesn't exist$/) { exit 1; } @@ -86,7 +86,7 @@ while( ) { } $lastmsg = $_; } -close( PIPE ); +close( $pipe ); if ($?) { print "$lastmsg"; die "Bad exit status $? from wanna-build\n"; diff --git a/bin/wb-graph b/bin/wb-graph index 2a952d0..fb326e8 100755 --- a/bin/wb-graph +++ b/bin/wb-graph @@ -43,9 +43,9 @@ foreach $arch (@archs) { my($lastmsg, %n_state, $total, %n_builder, $pu_total); $pu_total = 0; $n_state{"Installed"} = 0; -open( PIPE, "wanna-build --database=$arch/build-db --dist=$dist --list=all |" ) +open( my $pipe, '-|', "wanna-build --database=$arch/build-db --dist=$dist --list=all" ) or die "Cannot spawn wanna-build: $!\n"; -while( ) { +while( <$pipe> ) { if (/^Database for $dist doesn't exist$/) { last; } @@ -64,7 +64,7 @@ while( ) { } $lastmsg = $_; } -close( PIPE ); +close( $pipe ); if ($?) { print ", 0, 0"; } else { diff --git a/lib/WB/QD.pm b/lib/WB/QD.pm index 58b4527..8391fc3 100644 --- a/lib/WB/QD.pm +++ b/lib/WB/QD.pm @@ -15,15 +15,15 @@ sub readsourcebins { my $pas = {}; local($/) = "\n"; - open(PAS, '<', $pasfile); - while() { + open(my $pas, '<', $pasfile); + while(<$pas>) { chomp; s,\s*#.*,,; next unless $_; my ($p, $c) = split(/:\s*/); $pas->{$p} = { arch => [ split(/\s+/, $c) ], mode => substr($c, 0, 1) ne '!' }; } - close PAS; + close $pas; my $srcs = {}; local($/) = ""; # read in paragraph mode -- 2.39.2