Solved

Basic text file appending not working!

Posted on 2003-12-08
3
214 Views
Last Modified: 2013-12-25
Hi,
i am trying to write to a simple text file on my windows server.

I can open the file and read the contents. However I cannot seem to be able to write to the file. I think the code is right. But it simply does not append anything to the text file.


print "Content-type: text/html\n\n";
$file = 'path\checkbook.txt';
open (CHECKBOOK, "+>>" . $file) or die "cannot open $file: $!";      
flock (CHECKBOOK, 2) or die "cannot flock $file: $!";
my @file_contents = <CHECKBOOK>;  
$file_contents[0] = "Browser was " . $ENV{'HTTP_USER_AGENT'} . "<BR>\n";
$file_contents[1] = "They came from " . $ENV{'HTTP_REFERER'} . "<BR>\n";
$file_contents[2] = "The remote address was " . $ENV{'REMOTE_ADDR'} . "<BR>\n";
$file_contents[3] = "The remote host was " . $ENV{'REMOTE_HOST'} . "<BR>\n";
print CHECKBOOK @file_contents;  # print the new info to the file  
close (CHECKBOOK);

Can anyone help?

Thanks,
Owen
0
Comment
Question by:owenthornton
  • 2
3 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 9899141
To append to a file, do something like

my $file = '/path/checkbook.txt';
open CHECKBOOK, ">>$file" or die "Can not append to $file $!\n";
flock CHECKBOOK,2;

print CHECKBOOK <<EOF;
Browser was  $ENV{'HTTP_USER_AGENT'} <br>
They came from  $ENV{'HTTP_REFERER'} <br>
The remote address was  $ENV{'REMOTE_ADDR'} <br>
The remote host was  $ENV{'REMOTE_HOST'} <br>
EOF

close CHECKBOOK;

0
 

Author Comment

by:owenthornton
ID: 9902144
Hi Tintin,

I stuck the code in the cgi file. That is all code the cgi file has in it, since under windows, i don't think you have to "declare" the path to perl.

with that code I get a

'pathtoscript/flatfile.cgi' script produced no output

error message.

Any ideas?
0
 
LVL 48

Accepted Solution

by:
Tintin earned 50 total points
ID: 9926596
You get the message "produced no output" because that's exactly what the script does.

If you want some output, add something like

print "Information written to $file\n";
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
need a quick help to fix the script logic 4 63
Ready Made PHP Scripts 5 62
inactive users 13 70
React or Angular? 6 51
In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now