Obsolete
/
dnsmanagerv1
Archived
3
0
Fork 0
This repository has been archived on 2024-06-18. You can view files and clone it, but cannot push or open issues/pull-requests.
dnsmanagerv1/lib/fileutil.pm

47 lines
928 B
Perl
Raw Normal View History

package fileutil;
use v5.14;
use URI;
use Exporter 'import';
# what we want to export eventually
our @EXPORT_OK = qw/read_file write_file/;
# bundle of exports (tags)
our %EXPORT_TAGS = ( all => [qw/read_file write_file/] );
sub read_file {
my ($filename) = @_;
if($filename =~ "://")
{
my $fileuri = URI->new($filename);
$filename = $fileuri->path;
}
open my $entry, '<:encoding(UTF-8)', $filename or
die "Impossible d'ouvrir '$filename' en lecture : $!";
local $/ = undef;
my $all = <$entry>;
close $entry;
return $all;
}
sub write_file {
my ($filename, $data) = @_;
if($filename =~ "://")
{
my $fileuri = URI->new($filename);
$filename = $fileuri->path;
}
open my $sortie, '>:encoding(UTF-8)', $filename or
die "Impossible d'ouvrir '$filename' en écriture : $!";
print $sortie $data;
close $sortie;
}
1;