in reply to Quick Question - Append File at Beginning?
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));
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Quick Question - Append File at Beginning?
by hippo (Archbishop) on Nov 16, 2013 at 11:12 UTC | |
by BillKSmith (Monsignor) on Nov 16, 2013 at 13:58 UTC | |
by taint (Chaplain) on Nov 16, 2013 at 21:23 UTC | |
by afoken (Chancellor) on Nov 17, 2013 at 11:47 UTC | |
by taint (Chaplain) on Nov 17, 2013 at 19:33 UTC |