Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2002
    Thanked 0 Times in 0 Posts

    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.

  2. #2
    New Coder
    Join Date
    Sep 2002
    Up North (UK)
    Thanked 0 Times in 0 Posts

    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,



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts