You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
928 B

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;