How can I insert a line at the beginning of a file with Perl's Tie::File?
- by thebourneid
I'm trying to insert/add a line 'COMMENT DUMMY' at the beginnig of a file as a first row if /PATTERN/ not found.
I know how to do this with OPEN CLOSE function. Probably after reading the file it should look something like this:
open F, ">", $fn or die "could not open file: $!"; ;
print F "COMMENT DUMMY\n", @array;
close F;
But I have a need to implement this with the use of the Tie::File function and don't know how.
use strict;
use warnings;
use Tie::File;
my $fn = 'test.txt';
tie my @lines, 'Tie::File', $fn or die "could not tie file: $!";
untie @lines;