The operation you request is not typically supported by underlying filesystem. OS/400 I think supports record-based filesmembers where you can insert/delete with abandon? For ext4, etc., this operation will be both costly and inherently dangerous.
This said, in case you insist on DWIM, a simple mmap can do the trick, provided it is available.
Update: use map_handle instead of map_file.
Prev version:no warnings; use File::Map ':all'; open(my $fh, '+>>', shift) or die; # open/mmap modes must ~~ my $off = $fh->tell; print $fh join " ", @ARGV; $fh->flush; # rotate in place map_handle(my $mmap, $fh, '+<'); substr($mmap, 0, 0, substr($mmap, $off));
no strict; no warnings; use File::Map ':all'; my $fnam = shift @ARGV or die; open(my $fh, '>>', $fnam) or die; my $off = -s $fh; print $fh join " ", @ARGV; close $fh; # ! # rotate in place map_file my $mmap, $fnam, '+<'; substr($mmap, 0, 0, substr($mmap, $off));
In reply to Re: Quick Question - Append File at Beginning?
by oiskuu
in thread Quick Question - Append File at Beginning?
by jdlev
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |