mirror of
https://git.proxmox.com/git/pve-installer
synced 2025-06-06 04:38:28 +00:00

The assignment to () is confusing, as that's effectively identical with not assigning it at all and later auto-vivify it to an array ref, make that more explicit instead. Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
45 lines
789 B
Perl
45 lines
789 B
Perl
package Proxmox::Sys::File;
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use IO::File;
|
|
|
|
use base qw(Exporter);
|
|
our @EXPORT_OK = qw(file_read_firstline file_read_all file_write_all);
|
|
|
|
sub file_read_firstline {
|
|
my ($filename) = @_;
|
|
|
|
my $fh = IO::File->new ($filename, "r");
|
|
return undef if !$fh;
|
|
|
|
my $res = <$fh>;
|
|
chomp $res if $res;
|
|
$fh->close;
|
|
|
|
return $res;
|
|
}
|
|
|
|
sub file_read_all {
|
|
my ($filename) = @_;
|
|
|
|
my $fh = IO::File->new($filename, "r") || die "can't open '$filename' - $!\n";
|
|
|
|
local $/; # slurp mode
|
|
my $content = <$fh>;
|
|
close $fh;
|
|
|
|
return $content;
|
|
}
|
|
|
|
sub file_write_all {
|
|
my ($filename, $content) = @_;
|
|
|
|
my $fd = IO::File->new(">$filename") || die "unable to open file '$filename' - $!\n";
|
|
print $fd $content;
|
|
$fd->close();
|
|
}
|
|
|
|
1;
|