tags:

views:

100

answers:

4

I used a Perl helper to code this. It looks I am missing a character or something. I need to write the new text to the top of the text file.

open (LOGFILE, ">> complete.txt") ; # writes new to the bottom

$datetime = localtime ;

print LOGFILE "\n" ;

print LOGFILE $datetime\n" ;
print LOGFILE "$name\n" ;
print LOGFILE "Has completed the work\n" ;

close (LOGFILE) ;
+3  A: 

Hi,

This link explains it better than I could,

How to insert text at the beginning of a file using Perl

Graeme Smyth
+3  A: 

You can use the Tie::File module to enable access to the file via an array:

use Tie::File;
my @array;
tie @array, 'Tie::File', 'complete.txt' or die $!;
unshift @array, localtime."\n";
eugene y
+8  A: 

This is answered in the Perl FAQ.

How do I change, delete, or insert a line in a file, or append to the beginning of a file?

If you're programming in Perl, then it's well worth taking an hour or so to skim the FAQ. It's full of useful information.

davorg
A: 

Thanks everyone for the quick answers, was only a few minutes ago. This seems to work great

it is what pascal recomended, I just did'nt know how to do that.

open (LOGFILE, "complete.txt") ;
@data = ;
close (LOGFILE);

open (LOGFILE, ">complete.txt") ;

$datetime = localtime ; 

print LOGFILE "\n" ; 

print LOGFILE $datetime\n" ; 
print LOGFILE "$name\n" ; 
print LOGFILE "Has completed the work\n" ; 

foreach (@data) {
    print LOGFILE $_;
}

close (LOGFILE) ;
William
The project is really alot more extensive then may appear, plaease have a look here I am working on it live, a video Blogger on my website. Thanks http://williamwendland.com/vidiblog
William