?
Solved

Basic text file appending not working!

Posted on 2003-12-08
3
Medium Priority
?
224 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
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 …
Suggested Courses

801 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