View Full Version : Read file /text data into a web app.

10-09-2002, 09:06 PM
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.

10-14-2002, 12:51 PM

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:
while (<IN> ) {
print $_; }Hope this helps,