Results 1 to 4 of 4
  1. #1
    Full Member c4's Avatar
    Join Date
    January 18th, 2005
    Posts
    488
    How can I do this in CGI:

    Here's what I wanna know:

    - I have a file named "file.txt"
    - In this file I have many words, seperated by '%%'
    (%%wrod1%%word2%%word3 etc ...)

    - Now somebody wants to add a word. What code should I put to make the script first seperate those words (I know this but anyway), then check if a word is already listed and if not, add it to list?

    :confused:

    I tried something with 'foreach' function, but can't seem to get it working.

    Thanks in advance!

  2. #2
    ABW Ambassador
    Join Date
    January 18th, 2005
    Location
    ÄúsTrálíĺ
    Posts
    1,372
    This is rather crude, and may need optimising if it's to be used for any large amount of data, but it's a starting point.

    btw... i haven't tested this, but it should come close to working.
    -------------------------------

    $word="yourwordhere";

    open(FILE,"file.txt");
    $data = (FILE); ###### ) = >....( = <
    close(FILE);
    @pairs = split(/\%%/,$data); # split at %%

    $found="no";

    foreach $pair (@pairs) {
    if ("$word" eq "$pair") {
    $found="yes";
    }
    }

    if ("$found" eq "no") { #add to file
    open(FILE,">>$file.txt");
    binmode(FILE);
    print FILE "$word%%";
    close(FILE);
    }

    [ edit: you'll have to change highlighted line ######. This post kept removing the > and <'s]
    it should read<pre class="ip-ubbcode-code-pre">&lt;FILE&gt;</pre>

    [edit #3: arrrggghh.. even the code command doesn't work ]
    anyway, if you don't understand what you have to change, let me know.. if should be {lessthan}FILE{greaterthan} on the line i've shown

    [ 03-12-2002: Message edited by: Pete ]

  3. #3
    Full Member c4's Avatar
    Join Date
    January 18th, 2005
    Posts
    488
    Thanks a lot!

    I'll try this code first thing tomorrow (it's quite simmilar than the one I wrote but didn't work so I guess I was very close...) and will come back to you if I have any problems.

    c4

  4. #4
    Full Member c4's Avatar
    Join Date
    January 18th, 2005
    Posts
    488
    Hi, Pete!

    I just tested this code, it works [img]/infopop/emoticons/icon_smile.gif[/img] Just what I need ...

  5. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Domain issue since server change - cgi-sys/defaultwebpage.cgi
    By mobilebadboy in forum Domains & Hosting
    Replies: 6
    Last Post: July 31st, 2011, 10:47 PM
  2. CGI Timeout
    By Trefoil in forum Cusimano.com Scripts
    Replies: 3
    Last Post: April 24th, 2004, 10:35 PM
  3. cgi-world/cgiwrap/domain/cgi-bin/amazon.pl
    By KariBon in forum Cusimano.com Scripts
    Replies: 1
    Last Post: February 10th, 2003, 01:54 PM
  4. please talk me through this cgi
    By SpaceBandit in forum Programming / Datafeeds / Tools
    Replies: 14
    Last Post: February 19th, 2002, 12:13 PM
  5. Anybody could with CGI and smartsearch.cgi??
    By natedog in forum Programming / Datafeeds / Tools
    Replies: 39
    Last Post: January 16th, 2002, 07:22 PM

Posting Permissions

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