File::Util is an easy, versatile, portable file handling module.
File::Util provides a comprehensive toolbox of utilities to automate all kinds of common tasks on file / directories. Its purpose is to do so in the most portable manner possible so that users of this module won't have to worry about whether their programs will work on other OSes and machines.
SYNOPSIS
use File::Util;
my($f) = File::Util->new();
my($content) = $f->load_file('foo.txt');
$content =~ s/this/that/g;
$f->write_file(
'file' => 'bar.txt',
'content' => $content,
'bitmask' => 0644
);
$f->write_file(
'file' => 'file.bin', 'content' => $binary_content, '--binmode'
);
my(@lines) = $f->load_file('randomquote.txt', '--as-lines');
my($line) = int(rand(scalar @lines));
print $lines[$line];
my(@files) = $f->list_dir('/var/tmp', qw/ --files-only --recurse /);
my(@textfiles) = $f->list_dir('/var/tmp', '--pattern=.txt$');
if ($f->can_write('wibble.log')) {
my($HANDLE) = $f->open_handle(
'file' => 'wibble.log',
'mode' => 'append'
);
print $HANDLE "Hello World! It's ", scalar localtime;
close $HANDLE
}
my($log_line_count) = $f->line_count('/var/log/httpd/access_log');
print "My file has a bitmask of " . $f->bitmask('my.file');
print "My file is a " . join(', ', $f->file_type('my.file')) . " file."
warn 'This file is binary!' if $f->isbin('my.file');
print "My file was last modified on " .
scalar localtime($f->last_modified('my.file'));
# ...and _lots_ more
Product's homepage
Requirements:
· Perl