in reply to writing to the top of a file
Tie::File isn't a standard module but its easily installed as it is pure Perl (i.e. doesn't need a C compiler installed).#!/usr/bin/perl use strict; use warnings; use Tie::File; use Data::Dumper; my $file = "file.txt"; my @lines; #tie @lines, 'Tie::File', $file || die $!; tie @lines, 'Tie::File', $file or die $!; my @tmp = splice @lines; push @lines, <STDIN>; push @lines, @tmp; untie @lines;
CC
Updated: changed '||' to 'or'.
Another update
Given that whatever solution you choose will be running from a web page (via CGI), have you given any thought file locking? What if multiple copies of the CGI script are running at the same time? You could potentially lose a lot of data...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: writing to the top of a file
by neniro (Priest) on May 20, 2004 at 10:01 UTC | |
|
Re: Re: writing to the top of a file
by Somni (Friar) on May 20, 2004 at 03:23 UTC | |
|
Re: Re: writing to the top of a file
by BrowserUk (Patriarch) on May 20, 2004 at 12:11 UTC |