summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaouda Lo <daouda@mandriva.com>2005-11-15 14:32:44 +0000
committerDaouda Lo <daouda@mandriva.com>2005-11-15 14:32:44 +0000
commit4ea2af164dd4b7e2b4d5ca5e2df573403db4bfc9 (patch)
tree22e5ddb24a061bf0221fab7d76840655abaabdaf
parent238f2e7ed6e84205f627a51f4701a302c8b388bc (diff)
downloadperl-MDK-Common-4ea2af164dd4b7e2b4d5ca5e2df573403db4bfc9.tar
perl-MDK-Common-4ea2af164dd4b7e2b4d5ca5e2df573403db4bfc9.tar.gz
perl-MDK-Common-4ea2af164dd4b7e2b4d5ca5e2df573403db4bfc9.tar.bz2
perl-MDK-Common-4ea2af164dd4b7e2b4d5ca5e2df573403db4bfc9.tar.xz
perl-MDK-Common-4ea2af164dd4b7e2b4d5ca5e2df573403db4bfc9.zip
- extend cat_ to handle multiple files
-rw-r--r--MDK/Common/File.pm10
1 files changed, 6 insertions, 4 deletions
diff --git a/MDK/Common/File.pm b/MDK/Common/File.pm
index 372d1c7..7aea145 100644
--- a/MDK/Common/File.pm
+++ b/MDK/Common/File.pm
@@ -18,12 +18,13 @@ MDK::Common::File - miscellaneous file/filename manipulation functions
returns the dirname/basename of the file name
-=item cat_(FILENAME)
+=item cat_(FILES)
-returns the file content: in scalar context it returns a single string, in
+returns the files contents: in scalar context it returns a single string, in
array context it returns the lines.
-If the file doesn't exist, it returns undef
+If no file is found, undef is returned
+
=item cat_or_die(FILENAME)
@@ -131,7 +132,8 @@ our %EXPORT_TAGS = (all => [ @EXPORT_OK ]);
sub dirname { local $_ = shift; s|[^/]*/*\s*$||; s|(.)/*$|$1|; $_ || '.' }
sub basename { local $_ = shift; s|/*\s*$||; s|.*/||; $_ }
-sub cat_ { open(my $F, $_[0]) or return; my @l = <$F>; wantarray() ? @l : join '', @l }
+sub cat_a_file { open(my $F, $_[0]) or return; my @l = <$F>; @l }
+sub cat_ { my @l; @l = (@l, cat_a_file($_)) foreach @_; 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; open(my $F, ">$f") or die "output in file $f failed: $!\n"; print $F $_ foreach @_; 1 }