Go Back   CodingForums.com > :: Server side development > Perl/ CGI

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-09-2002, 09:06 PM   PM User | #1
Sscotties
New Coder

 
Join Date: Aug 2002
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Sscotties is an unknown quantity at this point
Read file /text data into a web app.

Greetings from a java programmer,

I have used this piece of code which has worked REALLY WELL sending data from a java applet;-


#!/usr/bin/perl -w
$address = "My specified route on the server + $filename";

open(OUT, ">$address");
print "content-type: text/plain\n\n";
while (<>) {
print OUT $_;
print $_;
}
close (OUT);
exit 0;
# end of script


What I would LOVE is to have a generic script to read in data from a file specified in the $address eg --->
$address = "/myData/users/jonsFile.txt";

I did a search before submitting this and found this;-


#!/usr/bin/perl -w
# use strict; // blocked, but what does this do ?
$fileref = "myFile.txt";
$file = "My specified route on the server + $filename";
chomp(my $line = <STDIN> ); // don't get this bit?
open (DUMP, ">>$file") || die "Couldn't open $fileref, sorry";
print DUMP "[",scalar localtime,"] $line\n";
close DUMP;
print "Information sent from $fileref\n";
# end of script


I made one or two changes here and there, so I hope I haven't cocked it up.


So, folks - please! Can I have a generic 'readThisFile' script?

Thank you very much in advance to all who read this post.

PS: security isn't an issue I think as only the specfied files will be accessible according to each script.
Sscotties is offline   Reply With Quote
Old 10-14-2002, 12:51 PM   PM User | #2
fivesidecube
New Coder

 
Join Date: Sep 2002
Location: Up North (UK)
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
fivesidecube is an unknown quantity at this point
Sscotties,

You need to turn around the open(OUT, ">$address"); to read open(IN, "<$address");

Now you can read from the IN filehandle and write to the standard output:
Code:
while (<IN> ) { 
print $_; }
Hope this helps,

Fivesidecube
fivesidecube is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:23 PM.


Advertisement
Log in to turn off these ads.