Making a script write to a file (take 2)

D

Dave

G'day all

I'm trying to get a script to write (append) data to the bottom line
of a text file (*.dat). I know the variables I want to add but can't
do it.
I need to append something that looks like this...

$invoice|$date|Your Order has been received

Any suggestions would be helpful.

Cheers
Dave.
 
J

John Bokma

Dave said:
G'day all

I'm trying to get a script to write (append) data to the bottom line
of a text file (*.dat). I know the variables I want to add but can't
do it.
I need to append something that looks like this...

$invoice|$date|Your Order has been received

Any suggestions would be helpful.

Is it possible that multiple processes add at the same time?
 
L

Lao Coon

(e-mail address removed) (Dave) wrote in
G'day all

I'm trying to get a script to write (append) data to the bottom line
of a text file (*.dat). I know the variables I want to add but can't
do it.
I need to append something that looks like this...

$invoice|$date|Your Order has been received

Any suggestions would be helpful.

Read perldoc perlopentut

open OUT, ">> file.dat" or die "Could not open file.dat : $!";

print OUT "$invoice|$date|Your Order has been received\n";

close OUT;



Lao
 
D

Dave

Abigail said:
What have you tried so far?


Abigail

Abigail,

I've been working on this.....

$orders_dat = "http//....path to file"

open(ORDERS,">>$orders_dat"); print ORDERS
"$invoice$delimiter$date$delimiter$processing_msg\n"; close(ORDERS);

Cheers
Dave.
 
V

Vlad Tepes

Dave said:
I've been working on this.....

$orders_dat = "http//....path to file"

open(ORDERS,">>$orders_dat"); print ORDERS
"$invoice$delimiter$date$delimiter$processing_msg\n"; close(ORDERS);

open() doesn't accept urls as arguments. If the file is on a remote
system you can't use open().

If this is cgi, you must remember to lock your files. Otherwise
simultaneous updates might ruin your files. See 'perldoc -f flock'
for details on how to do this.

Regards,
 
P

Philip

$orders_dat = "http//....path to file"

that's your problem. you need to use the real system path to the
file, not it's HTTP URL.
 
D

Dave

that's your problem. you need to use the real system path to the
file, not it's HTTP URL.

so if I change it to....

$orders_dat = "/home/user/public_html/web/orders.dat"

open(ORDERS,">>$orders_dat");
print ORDERS
"$invoice$delimiter$date$delimiter$processing_msg\n"; close(ORDERS);

It should work! I'll give it a whirl.
Thanks for the constructive criticism!

Dave.
 
T

Tony Curtis

On 11 Sep 2003 18:22:52 -0700,
(e-mail address removed) (Philip) wrote in message

(An http URL does not refer to a file.)
so if I change it to....
$orders_dat = "/home/user/public_html/web/orders.dat"
open(ORDERS,">>$orders_dat"); print ORDERS
"$invoice$delimiter$date$delimiter$processing_msg\n";
close(ORDERS);
It should work! I'll give it a whirl. Thanks for the
constructive criticism!

Don't forget you have to deal with locking.

perldoc -q lock

hth
t
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,085
Members
48,773
Latest member
Kaybee

Latest Threads

Top