Hello I'm discovering perl and cgi scripts. I'm trying to modify the content of a file i've written in. The problem is that i can't position the pointer to the beginning of the file. I've been trying to use seek(OUTF,0,0); but it does not work. So my question is: is there a possibility to modify the content of a file, without having to create a temporary file.
This is the piece of code i'm trying to make working.
seek(OUTF,0,0);
@data = <INF>;
if (@data[0]<1)
{
print OUTF "1\n";
}
else
{
$var=1+@data[0];
print OUTF "$var\n";
seek(OUTF,0,2);
}
print OUTF "$FORM{'name'}|$FORM{'description'}|$FORM{'price'}|$FORM{'supplier'}|$FORM{'stock'}\n";
close(OUTF);
Basically, i want to insert a number in the first line of the file who will indicate the number of lines in the file. Every time a new record is inserted, this number is incremented. I just need to know how i can write at the beginning of the file.
Thanks
Thomas
This is the piece of code i'm trying to make working.
seek(OUTF,0,0);
@data = <INF>;
if (@data[0]<1)
{
print OUTF "1\n";
}
else
{
$var=1+@data[0];
print OUTF "$var\n";
seek(OUTF,0,2);
}
print OUTF "$FORM{'name'}|$FORM{'description'}|$FORM{'price'}|$FORM{'supplier'}|$FORM{'stock'}\n";
close(OUTF);
Basically, i want to insert a number in the first line of the file who will indicate the number of lines in the file. Every time a new record is inserted, this number is incremented. I just need to know how i can write at the beginning of the file.
Thanks
Thomas