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

    Simple bit of code to add please.

    #!/usr/bin/perl

    # HOW DO I DO THIS ?:
    # open up a local *.txt file (eg. in 'cgi-bin')
    # get the value of an integer there
    # increment it by 1 in the external file and
    # assign the variable $i the new value
    # THEREFORE ...
    # reading page1.txt, page2.txt, page3 etc,

    $address = "/public_html/page+$i+.txt";
    open(OUT, ">$address");
    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
    You could try this:

    Code:
    #!/usr/bin/perl
    
    $i = 0; # what the page you want to start at is
    
    # "-e" is a command interprating to "does it exist?"
    
    while (-e "/cgi-bin/page$i.txt") {
     # whatever you want to do when the file is opened:
     # eg: 
     # open(FILE,"/cgi-bin/page$i.txt");
     # @file = <FILE>; close(FILE);
     # foreach $file (@file) { print $file; }
    
     ++$i; # Do not remove this! Increases the $i value.
    }
    
    print $i; # shows the total number of files opened.
    Note. If you are going to this above, you can not declair the variable $address and expect it to work as it wont update.

  • #3
    New Coder
    Join Date
    Aug 2002
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SUPERB!

    Thanx chief ego, it looks perfect.


  •  

    Posting Permissions

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