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

    Sorry, and also ???

    Sorry to be a pain, but I am trying to get to grips with this stuff and I am attempting to learn cgi/perl, forgive me for using this as a short-cut. What I want is something similar to this that appends the file rather than rewrites over it, so that each time it is accessed only the most recent submission is added in a new line of user input to the "results.txt" file.

    #!/usr/bin/perl
    open(OUT, ">/my_info/results.txt");
    print "content-type: text/plain\n\n";

    while (<>) {
    print OUT $_;
    print $_;
    }
    close (OUT);
    exit 0;

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Brisbane, Australia
    Posts
    181
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Instead of using ">" ... use ">>".

    eg:

    Code:
    open(DATA,">>file.txt");
     print DATA "HELLO";
    close (DATA);
    This is if you want to add it to the bottom of a text file.

    EG:

    Textfile BEFORE running the script:

    my name
    your name
    his name
    her name

    Textfile AFTER running the script:

    my name
    your name
    his name
    her name
    HELLO
    Last edited by mr_ego; 08-23-2002 at 06:48 AM.

  • #3
    New Coder
    Join Date
    Aug 2002
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's that simple eh?

    Sorry, I've come accross the '>>' before and it rang some kinda bells as soon as I read your reply. I must admit, there's a wonderful simplicity about perl that it quite compelling.

    You have encouraged me to take a dive into my studies just a little bit further. I'm starting to see it's appeal now.

    Thank you once again.


  •  

    Posting Permissions

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