CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Perl/ CGI (http://www.codingforums.com/forumdisplay.php?f=5)
-   -   Read file /text data into a web app. (http://www.codingforums.com/showthread.php?t=7712)

Sscotties 10-09-2002 09:06 PM

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.

fivesidecube 10-14-2002 12:51 PM

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


All times are GMT +1. The time now is 10:58 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.