summaryrefslogtreecommitdiffstats
path: root/MDK/Common
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2004-04-28 11:25:26 +0000
committerPascal Rigaux <pixel@mandriva.com>2004-04-28 11:25:26 +0000
commit11a4d7c3b70b617bdce862eb466306d9673e66e7 (patch)
tree813c10472765c23ae9b109e763101e72da4ac4d7 /MDK/Common
parent26ebc5ad59c9044e10fa55ebf57f1aa245738e92 (diff)
downloadperl-MDK-Common-11a4d7c3b70b617bdce862eb466306d9673e66e7.tar
perl-MDK-Common-11a4d7c3b70b617bdce862eb466306d9673e66e7.tar.gz
perl-MDK-Common-11a4d7c3b70b617bdce862eb466306d9673e66e7.tar.bz2
perl-MDK-Common-11a4d7c3b70b617bdce862eb466306d9673e66e7.tar.xz
perl-MDK-Common-11a4d7c3b70b617bdce862eb466306d9673e66e7.zip
- deprecate "open F, ..." prefering "open(my $F, ...)"
- fix an internal_error
Diffstat (limited to 'MDK/Common')
-rw-r--r--MDK/Common/File.pm23
-rw-r--r--MDK/Common/System.pm4
2 files changed, 13 insertions, 14 deletions
diff --git a/MDK/Common/File.pm b/MDK/Common/File.pm
index bf4cd01..a5f95d3 100644
--- a/MDK/Common/File.pm
+++ b/MDK/Common/File.pm
@@ -122,11 +122,11 @@ use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK);
sub dirname { local $_ = shift; s|[^/]*/*\s*$||; s|(.)/*$|$1|; $_ || '.' }
sub basename { local $_ = shift; s|/*\s*$||; s|.*/||; $_ }
-sub cat_ { local *F; open F, $_[0] or return; my @l = <F>; wantarray() ? @l : join '', @l }
-sub cat_or_die { local *F; open F, $_[0] or die "can't read file $_[0]: $!\n"; my @l = <F>; wantarray() ? @l : join '', @l }
+sub cat_ { open(my $F, $_[0]) or return; my @l = <$F>; wantarray() ? @l : join '', @l }
+sub cat_or_die { open(my $F, $_[0]) or die "can't read file $_[0]: $!\n"; my @l = <$F>; wantarray() ? @l : join '', @l }
sub cat__ { my ($f) = @_; my @l = <$f>; wantarray() ? @l : join '', @l }
-sub output { my $f = shift; local *F; open F, ">$f" or die "output in file $f failed: $!\n"; print F foreach @_; 1 }
-sub append_to_file { my $f = shift; local *F; open F, ">>$f" or die "output in file $f failed: $!\n"; print F foreach @_; 1 }
+sub output { my $f = shift; open(my $F, ">$f") or die "output in file $f failed: $!\n"; print $F $_ foreach @_; 1 }
+sub append_to_file { my $f = shift; open(my $F, ">>$f") or die "output in file $f failed: $!\n"; print $F $_ foreach @_; 1 }
sub output_p { my $f = shift; mkdir_p(dirname($f)); output($f, @_) }
sub output_with_perm { my ($f, $perm, @l) = @_; mkdir_p(dirname($f)); output($f, @l); chmod $perm, $f }
sub linkf { unlink $_[1]; link $_[0], $_[1] }
@@ -186,9 +186,9 @@ sub cp_with_option {
require MDK::Common::System;
MDK::Common::System::syscall_('mknod', $dest, $stat[2], $stat[6]) or die "mknod failed (dev $dest): $!";
} else {
- local *F; open F, $src or die "can't open $src for reading: $!\n";
- local *G; open G, "> $dest";
- local $_; while (<F>) { print G $_ }
+ open(my $F, $src) or die "can't open $src for reading: $!\n";
+ open(my $G, "> $dest");
+ local $_; while (<$F>) { print $G $_ }
chmod((stat($src))[2], $dest);
}
}
@@ -201,8 +201,8 @@ sub cp_af { cp_with_option('af', @_) }
sub touch {
my ($f) = @_;
unless (-e $f) {
- local *F;
- open F, ">$f";
+ my $F;
+ open($F, ">$f");
}
my $now = time();
utime $now, $now, $f;
@@ -286,9 +286,8 @@ sub expand_symlinks {
sub openFileMaybeCompressed {
my ($f) = @_;
-e $f || -e "$f.gz" or die "file $f not found";
- local *F;
- open F, -e $f ? $f : "gzip -dc $f.gz|" or die "file $f is not readable";
- *F;
+ open(my $F, -e $f ? $f : "gzip -dc $f.gz|") or die "file $f is not readable";
+ $F;
}
sub catMaybeCompressed { cat__(openFileMaybeCompressed($_[0])) }
diff --git a/MDK/Common/System.pm b/MDK/Common/System.pm
index e4f5476..a864968 100644
--- a/MDK/Common/System.pm
+++ b/MDK/Common/System.pm
@@ -303,9 +303,9 @@ sub whereis_binary {
sub getVarsFromSh {
my %l;
- local *F; open F, $_[0] or return;
+ open(my $F, $_[0]) or return;
local $_;
- while (<F>) {
+ while (<$F>) {
s/#.*//; # remove comments
my ($v, $val, $val2) =
/^\s* # leading space