Insert A Line At The Beginning Of A File
Posted
by thebourneid
on Stack Overflow
See other posts from Stack Overflow
or by thebourneid
Published on 2010-05-21T23:47:03Z
Indexed on
2010/05/22
3:20 UTC
Read the original article
Hit count: 260
perl
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;
© Stack Overflow or respective owner