Skip to content

Commit

Permalink
Item1518: Two-argument "open" used. See page 207 of PBP.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@3946 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
OlivierRaginel authored and OlivierRaginel committed May 20, 2009
1 parent b81b96e commit 0f9c19e
Show file tree
Hide file tree
Showing 40 changed files with 80 additions and 80 deletions.
6 changes: 3 additions & 3 deletions core/lib/CPAN/lib/Locale/Maketext/Extract.pm
Expand Up @@ -110,7 +110,7 @@ sub read_po {
my $header = '';

local *LEXICON;
open LEXICON, $file or die $!;
open LEXICON, '<', $file or die $!;
while (<LEXICON>) {
(1 .. /^$/) or last;
$header .= $_;
Expand All @@ -132,7 +132,7 @@ sub write_po {
my ($self, $file, $add_format) = @_;

local *LEXICON;
open LEXICON, ">$file" or die "Can't write to $file$!\n";
open LEXICON, '>', $file or die "Can't write to $file$!\n";

print LEXICON $self->header;

Expand Down Expand Up @@ -296,7 +296,7 @@ sub extract_file {
my ($self, $file) = @_;
local($/, *FH);
open FH, $file or die $!;
open FH, '<', $file or die $!;
$self->extract($file => scalar <FH>);
close FH;
}
Expand Down
2 changes: 1 addition & 1 deletion core/lib/CPAN/lib/Locale/Maketext/Extract/Run.pm
Expand Up @@ -35,7 +35,7 @@ sub run {
my @po = @{$opts{o} || [($opts{d}||'messages').'.po']};

foreach my $file (@{$opts{f}||[]}) {
open FILE, $file or die "Cannot open $file: $!";
open FILE, '<', $file or die "Cannot open $file: $!";
while (<FILE>) {
push @ARGV, $_ if -r and !-d;
}
Expand Down
2 changes: 1 addition & 1 deletion core/lib/CPAN/lib/Text/Diff.pm
Expand Up @@ -187,7 +187,7 @@ sub diff {
unless defined $options->{"MTIME_$AorB"};

local $/ = "\n";
open F, "<$seq" or carp "$!: $seq";
open F, '<', $seq or carp "$!: $seq";
$seqs[$i] = [<F>];
close F;

Expand Down
4 changes: 2 additions & 2 deletions core/lib/Foswiki/Configure/Checker.pm
Expand Up @@ -110,11 +110,11 @@ sub checkCanCreateFile {
return File::Spec->catfile( @path, '' ) . ' is not writable';
}
my $txt1 = "test 1 2 3";
open( FILE, ">$name" )
open( FILE, '>', $name )
|| return 'Could not create test file ' . $name . ':' . $!;
print FILE $txt1;
close(FILE);
open( IN_FILE, "<$name" )
open( IN_FILE, '<', $name )
|| return 'Could not read test file ' . $name . ':' . $!;
my $txt2 = <IN_FILE>;
close(IN_FILE);
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Configure/Checkers/CGISetup.pm
Expand Up @@ -266,7 +266,7 @@ sub _loadDEPENDENCIES {
pop(@dir); # Cutting off trailing Foswiki.spec gives us lib dir
$from = File::Spec->catfile( @dir, 'DEPENDENCIES' );
my $d;
open( $d, '<' . $from ) || return 'Failed to load DEPENDENCIES: ' . $!;
open( $d, '<', $from ) || return 'Failed to load DEPENDENCIES: ' . $!;
my @perlModules;

foreach my $line (<$d>) {
Expand Down
6 changes: 3 additions & 3 deletions core/lib/Foswiki/Configure/FoswikiCfg.pm
Expand Up @@ -187,7 +187,7 @@ sub _getValueObject {
sub _parse {
my ( $file, $root, $haveLSC ) = @_;

open( F, "<$file" ) || return '';
open( F, '<', $file ) || return '';
local $/ = "\n";
my $open = undef;
my @settings;
Expand Down Expand Up @@ -284,7 +284,7 @@ sub save {
$lsc =~ s/Foswiki\.spec/LocalSite.cfg/;
}

if ( open( F, '<' . $lsc ) ) {
if ( open( F, '<', $lsc ) ) {
local $/ = undef;
$this->{content} = <F>;
close(F);
Expand All @@ -298,7 +298,7 @@ HERE
}

my $out = $this->_save();
open( F, '>' . $lsc )
open( F, '>', $lsc )
|| die "Could not open $lsc for write: $!";
print F $this->{content};
close(F);
Expand Down
4 changes: 2 additions & 2 deletions core/lib/Foswiki/Func.pm
Expand Up @@ -2435,7 +2435,7 @@ sub readFile {
my $name = shift;
my $data = '';
my $IN_FILE;
open( $IN_FILE, "<$name" ) || return '';
open( $IN_FILE, '<', $name ) || return '';
local $/ = undef; # set to read to EOF
$data = <$IN_FILE>;
close($IN_FILE);
Expand All @@ -2459,7 +2459,7 @@ __NOTE:__ Use this function only for the Plugin workarea, *not* for topics and a
sub saveFile {
my ( $name, $text ) = @_;
my $FILE;
unless ( open( $FILE, ">$name" ) ) {
unless ( open( $FILE, '>', $name ) ) {
die "Can't create file $name - $!\n";
}
print $FILE $text;
Expand Down
4 changes: 2 additions & 2 deletions core/lib/Foswiki/I18N.pm
Expand Up @@ -302,7 +302,7 @@ sub _discover_languages {
my $this = shift;

#use the cache, if available
if ( open LANGUAGE, "<$Foswiki::cfg{WorkingDir}/languages.cache" ) {
if ( open LANGUAGE, '<', "$Foswiki::cfg{WorkingDir}/languages.cache" ) {
foreach my $line (<LANGUAGE>) {
my ( $key, $name ) = split( '=', $line );
chop($name);
Expand All @@ -312,7 +312,7 @@ sub _discover_languages {
else {

#TODO: if the cache file don't exist, perhaps a warning should be issued to the logs?
open LANGUAGE, ">$Foswiki::cfg{WorkingDir}/languages.cache";
open LANGUAGE, '>', "$Foswiki::cfg{WorkingDir}/languages.cache";
foreach my $tag ( available_languages() ) {
my $h = Foswiki::I18N->get_handle($tag);
my $name = $h->maketext("_language_name");
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Net.pm
Expand Up @@ -380,7 +380,7 @@ s/([\n\r])(From|To|CC|BCC)(\:\s*)([^\n\r]*)/$1.$2.$3._fixLineLength($4)/geois;
$text = "$header\n\n$body"; # rebuild message

my $MAIL;
open( $MAIL, '|' . $Foswiki::cfg{MailProgram} )
open( $MAIL, '|', $Foswiki::cfg{MailProgram} )
|| die "ERROR: Can't send mail using Foswiki::cfg{MailProgram}";
print $MAIL $text;
close($MAIL);
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Store/VCHandler.pm
Expand Up @@ -818,7 +818,7 @@ sub saveFile {

mkPathTo($name);
my $FILE;
open( $FILE, '>' . $name )
open( $FILE, '>', $name )
|| throw Error::Simple(
'VCHandler: failed to create file ' . $name . ': ' . $! );
binmode($FILE)
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/UI.pm
Expand Up @@ -229,7 +229,7 @@ sub handleRequest {
'?', $req->query_string(), "\n";
print STDERR <F>, "\n";
close($F);
open( $F, '<' . $passthruFilename );
open( $F, '<', $passthruFilename );
}
$req->load($F);
close(F);
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/UI/Register.pm
Expand Up @@ -385,7 +385,7 @@ sub _requireVerification {

my $file = _codeFile( $data->{VerificationCode} );
my $F;
open( $F, ">$file" ) or throw Error::Simple( 'Failed to open file: ' . $! );
open( $F, '>', $file ) or throw Error::Simple( 'Failed to open file: ' . $! );
print $F '# Verification code', "\n";

# SMELL: wierd jiggery-pokery required, otherwise Data::Dumper screws
Expand Down
4 changes: 2 additions & 2 deletions core/lib/Foswiki/Users/HtPasswdUser.pm
Expand Up @@ -109,7 +109,7 @@ sub _readPasswd {
return $data;
}
my $IN_FILE;
open( $IN_FILE, "<$Foswiki::cfg{Htpasswd}{FileName}" )
open( $IN_FILE, '<', "$Foswiki::cfg{Htpasswd}{FileName}" )
|| throw Error::Simple(
$Foswiki::cfg{Htpasswd}{FileName} . ' open failed: ' . $! );
my $line = '';
Expand Down Expand Up @@ -159,7 +159,7 @@ sub _savePasswd {
my $db = shift;

umask(077);
open( FILE, ">$Foswiki::cfg{Htpasswd}{FileName}" )
open( FILE, '>', "$Foswiki::cfg{Htpasswd}{FileName}" )
|| throw Error::Simple(
$Foswiki::cfg{Htpasswd}{FileName} . ' open failed: ' . $! );

Expand Down
2 changes: 1 addition & 1 deletion core/lib/Monitor.pm
Expand Up @@ -41,7 +41,7 @@ sub get_stat_info {

# open and read the main stat file
my $_INFO;
if ( !open( $_INFO, "</proc/$_[0]/stat" ) ) {
if ( !open( $_INFO, '<', "/proc/$_[0]/stat" ) ) {

# Failed
return { vsize => 0, rss => 0 };
Expand Down
8 changes: 4 additions & 4 deletions core/pseudo-install.pl
Expand Up @@ -30,7 +30,7 @@ BEGIN

my $n = 0;
$n++ while ( -e "testtgt$n" || -e "testlink$n" );
open( F, ">testtgt$n" ) || die "$basedir is not writeable: $!";
open( F, '>', "testtgt$n" ) || die "$basedir is not writeable: $!";
print F "";
close(F);
eval {
Expand Down Expand Up @@ -135,7 +135,7 @@ sub installModule {
}

if ( -e "$manifest" ) {
open( F, "<$manifest" ) || die $!;
open( F, '<', "$manifest" ) || die $!;
foreach my $file (<F>) {
chomp($file);
next unless $file =~ /^\w+/;
Expand Down Expand Up @@ -325,7 +325,7 @@ sub enablePlugin {
my ( $module, $installing, $libDir ) = @_;
my $cfg = '';
print "Updating LocalSite.cfg\n";
if ( open( F, "<lib/LocalSite.cfg" ) ) {
if ( open( F, '<', "lib/LocalSite.cfg" ) ) {
local $/;
$cfg = <F>;
$cfg =~ s/\r//g;
Expand All @@ -348,7 +348,7 @@ sub enablePlugin {
}

if ($changed) {
if ( open( F, ">lib/LocalSite.cfg" ) ) {
if ( open( F, '>', "lib/LocalSite.cfg" ) ) {
print F $cfg;
close(F);
print(
Expand Down
6 changes: 3 additions & 3 deletions core/test/bin/make_big.pl
Expand Up @@ -56,7 +56,7 @@ sub getWords {
my $words = '';
my $word;
if (!$dict_fh) {
open($dict_fh, "<$dict") || die $!;
open($dict_fh, '<', $dict) || die $!;
}
while ($n) {
while ($n && ($word = <$dict_fh>)) {
Expand All @@ -65,7 +65,7 @@ sub getWords {
}
last unless $n;
close($dict_fh);
open($dict_fh, "<$dict");
open($dict_fh, '<', $dict);
}

return $words;
Expand Down Expand Up @@ -104,7 +104,7 @@ sub getWords {
$nextTopic++;
}
my $topic = "$opts{base}$nextTopic";
open(TOPIC, ">data/$web/$topic.txt") || die $!;
open(TOPIC, '>', "data/$web/$topic.txt") || die $!;
my $t = time();
print TOPIC <<FLUFF;
%META:TOPICINFO{author="ProjectContributor" date="$t" format="1.1" version="1"}%
Expand Down
2 changes: 1 addition & 1 deletion core/test/tinderbox/rebuild-deploy-test-if-new.pl
Expand Up @@ -66,7 +66,7 @@ BEGIN
chomp( my ( $rev, $author ) = `./latest-svn-checkin.pl` );

my $lastVersion = '';
if ( open( VERSION, LAST_BUILD ) )
if ( open( VERSION, '<', LAST_BUILD ) )
{
chomp( $lastVersion = <VERSION> );
close( VERSION );
Expand Down
6 changes: 3 additions & 3 deletions core/tools/admin/mrtg/twiki.pl
Expand Up @@ -27,7 +27,7 @@ sub analyseLogFile {
my $linesProcessed = 0;

die 'cannot find: '.$logFile unless ( -e $logFile ); #change this to throw, so caller can continue
open(logFile, $logFile);
open(logFile, '<', $logFile);
if ( $pos->{$logFile} ) {
seek(logFile, $pos->{$logFile}, 0);
}
Expand Down Expand Up @@ -75,7 +75,7 @@ sub analyseLogFile {
my %pos;
if (-e 'twiki_seek.cfg' ) {
#TODO: gonna need a lock file too
open(seekFile, 'twiki_seek.cfg');
open(seekFile, '<', 'twiki_seek.cfg');
while(<seekFile>) {
if ( /^(.*): (\d*)$/ ) {
$pos{$1} = $2;
Expand Down Expand Up @@ -114,7 +114,7 @@ sub analyseLogFile {
if ( $previousLog ) {
analyseLogFile($previousLog, \%pos, $timeRegex);
}
open(seekFile, '>twiki_seek.cfg');
open(seekFile, '>', 'twiki_seek.cfg');
foreach my $fileName (keys %pos) {
print seekFile $fileName.': '.$pos{$fileName}."\n";
}
Expand Down
2 changes: 1 addition & 1 deletion core/tools/autoBuildFoswiki.pl
Expand Up @@ -55,7 +55,7 @@
my $return = `$unitTests`;
my $errorcode = $? >> 8;
unless ($errorcode == 0) {
open(UNIT, "$foswikihome/Foswiki-UnitTests.log");
open(UNIT, '<', "$foswikihome/Foswiki-UnitTests.log");
local $/ = undef;
my $unittestErrors = <UNIT>;
close(UNIT);
Expand Down
4 changes: 2 additions & 2 deletions core/tools/benchmark/benchmark.Athens
Expand Up @@ -66,12 +66,12 @@ sub main
$thePathInfo = $query->path_info();
$theRemoteUser = $query->remote_user();
$theUrl = $query->url;
open(OF,'>/tmp/twiki_bm.cgi') || die "Store failed";
open(OF, '>', '/tmp/twiki_bm.cgi') || die "Store failed";
print OF Dumper(\$query, $thePathInfo, $theRemoteUser, $theUrl);
close(OF);
`chmod 777 /tmp/twiki_bm.cgi`
} else {
open(IF, "</tmp/twiki_bm.cgi") || die "Retrieve failed";
open(IF, '<', '/tmp/twiki_bm.cgi') || die "Retrieve failed";
undef $/;
my $blah = <IF>;
close(IF);
Expand Down
4 changes: 2 additions & 2 deletions core/tools/benchmark/benchmark.Beijing
Expand Up @@ -61,12 +61,12 @@ sub main
$theRemoteUser = $query->remote_user();
$theUrl = $query->url;

open(OF,'>/tmp/twiki_bm.cgi') || die "Store failed";
open(OF, '>', '/tmp/twiki_bm.cgi') || die "Store failed";
print OF Dumper(\$query, $thePathInfo, $theRemoteUser, $theUrl);
close(OF);
`chmod 777 /tmp/twiki_bm.cgi`
} else {
open(IF, "</tmp/twiki_bm.cgi") || die "Retrieve failed";
open(IF, '<', '/tmp/twiki_bm.cgi') || die "Retrieve failed";
undef $/;
my $blah = <IF>;
close(IF);
Expand Down
4 changes: 2 additions & 2 deletions core/tools/benchmark/benchmark.Cairo
Expand Up @@ -32,12 +32,12 @@ if( $ENV{'DOCUMENT_ROOT'} ) {
$theRemoteUser = $query->remote_user();
$theUrl = $query->url;

open(OF,'>/tmp/twiki_bm.cgi') || die "Store failed";
open(OF, '>', '/tmp/twiki_bm.cgi') || die "Store failed";
print OF Dumper(\$query, $thePathInfo, $theRemoteUser, $theUrl);
close(OF);
`chmod 777 /tmp/twiki_bm.cgi`
} else {
open(IF, "</tmp/twiki_bm.cgi") || die "Retrieve failed";
open(IF, '<', '/tmp/twiki_bm.cgi') || die "Retrieve failed";
undef $/;
my $blah = <IF>;
close(IF);
Expand Down
2 changes: 1 addition & 1 deletion core/tools/benchmark/countlines.pl
Expand Up @@ -14,7 +14,7 @@
}

foreach $i (split( /\s+/, $pms)) {
open($in, $i) or next;
open($in, '<', $i) or next;

$collect = 'code';
$module{code} = 0;
Expand Down
2 changes: 1 addition & 1 deletion core/tools/check_manifest.pl
Expand Up @@ -16,7 +16,7 @@

my %man;

open MAN, "< $manifest" or die "Can't open $manifest for reading: $!";
open MAN, '<', $manifest or die "Can't open $manifest for reading: $!";
while( <MAN> ) {
next if /^!include/;
$man{$1} = 1 if /^(\S+)\s+\d+$/;
Expand Down
2 changes: 1 addition & 1 deletion core/tools/check_requires.pl
Expand Up @@ -32,7 +32,7 @@
my %satisfied;
$m =~ s/\.pm$//; $m =~ s#^\./##; $m =~ s#/#::#g;
local $/ = "\n";
open(F, "<$file");
open(F, '<', $file);
my $inpod = 0;
my $base = '';
foreach my $line (<F>) {
Expand Down
2 changes: 1 addition & 1 deletion core/tools/check_translations
Expand Up @@ -29,7 +29,7 @@ sub extract {

sub list_translators {
for my $file (<locale/*.po>) {
open(PO, $file);
open(PO, '<', $file);
my $line;
while($line = <PO>, $line =~ /^#/) {
if ($line =~ m/^#\s*Foswiki\s*translation\s*for\s*(.*)$/) {
Expand Down

0 comments on commit 0f9c19e

Please sign in to comment.