Results 1 to 4 of 4
  1. #1
    Full Member c4's Avatar
    Join Date
    January 17th, 2005
    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?


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

    Thanks in advance!

  2. #2
    ABW Ambassador
    Join Date
    January 17th, 2005
    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.


    $data = (FILE); ###### ) = >....( = <
    @pairs = split(/\%%/,$data); # split at %%


    foreach $pair (@pairs) {
    if ("$word" eq "$pair") {

    if ("$found" eq "no") { #add to file
    print FILE "$word%%";

    [ 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 17th, 2005
    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.


  4. #4
    Full Member c4's Avatar
    Join Date
    January 17th, 2005
    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, 09:47 PM
  2. CGI Timeout
    By Trefoil in forum Scripts
    Replies: 3
    Last Post: April 24th, 2004, 09:35 PM
  3. cgi-world/cgiwrap/domain/cgi-bin/
    By KariBon in forum Scripts
    Replies: 1
    Last Post: February 10th, 2003, 12:54 PM
  4. please talk me through this cgi
    By SpaceBandit in forum Programming / Datafeeds / Tools
    Replies: 14
    Last Post: February 19th, 2002, 11:13 AM
  5. Anybody could with CGI and smartsearch.cgi??
    By natedog in forum Programming / Datafeeds / Tools
    Replies: 39
    Last Post: January 16th, 2002, 06: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