This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

duplicate in a file

Old posts that have not been replied to for several years.
Locked
E
EEggy
Op
Posts: 122
Joined: Thu Sep 26, 2002 11:46 pm

duplicate in a file

Post by EEggy »

hi, when i write logs to the file, how do i make sure it shouldn't write duplicates,?/ i mean if host is there, no need to write it again..

if {$socklog != ""} {
set x [open $socklog a+]
puts $x "[date] [time] - $host"
close $x
}

thanks
EEggy
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

either you make a loop and check each of the lines in the file, or you add the whole file to a list and use lsearch on it
Elen sila lúmenn' omentielvo
E
EEggy
Op
Posts: 122
Joined: Thu Sep 26, 2002 11:46 pm

Post by EEggy »

Thanks, could you please give me an example for "lsearch" ...
thanks again
EEggy
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

Code: Select all

while {![eof $file]} {
    set x [gets $file]
    lappend somelist "$x"
  }
if {[lsearch -glob $somelist "$host*"] == -1} { blabølabla add the thingie...
Elen sila lúmenn' omentielvo
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

There is no need to use gets in this situation.

You are reading the whole file, before you do the search. If the search was done on the fly, then yes, you could use this.

However, using the read command would be simpler.

Code: Select all

set somelist [split [read $file] \n]
E
EEggy
Op
Posts: 122
Joined: Thu Sep 26, 2002 11:46 pm

Post by EEggy »

thanks ppslim, but i am still confused..how do i set these codes to stop duplicates host...

if {$socklog != ""} {
set x [open $socklog a+]
puts $x "[date] [time] - $host"
close $x
}

i'll appreciate it
thanks
EEggy
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Place a little thought into it.

Before placeing a line in the file, you have to check for it's pre-existance.

This is what you have asked for, so this is what we have given you.
E
EEggy
Op
Posts: 122
Joined: Thu Sep 26, 2002 11:46 pm

Post by EEggy »

hmm ok so is this correct..

if {$socklog != ""} {
set x [open $socklog a+]
while {![eof $file]} {
set x [gets $file]
lappend somelist "$x"
}
if {[lsearch -glob $somelist "$host*"] == -1} { puts $x "[date] [time] - $host"}
close $x
}

thanks
EEggy
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

No - you will need to read over the "open" command, and find out about access flags.
E
EEggy
Op
Posts: 122
Joined: Thu Sep 26, 2002 11:46 pm

Post by EEggy »

may be now heh

if {$socklog != ""} {
set x [open $socklog r]
set somelist [split [read $file] \n]
set x [open $socklog a+]
while {![eof $file]} {
set x [gets $file]
lappend somelist "$x"
}
if {[lsearch -glob $somelist "$host*"] == -1} { puts $x "[date] [time] - $host"}
close $x
}

thanks
EEggy
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Maybe you should experiment on your own for a bit.

We will help along the way, but simply continously posting code, and expecting us to complete, fix or point your correctly every time, without giving the slightest though, to looking it over yourself (after making an attempt at correcting it).

As for the code: No.

Too be hoenst, I don't know where you got it from.

We are making pointers, showing you example code, that would help in your tracks, and you simply dump it in and expect it to work. THat is not how the forum operates.

You should take the code, review it, understand it, understand your own code and how the provided code could help you. You can then adapt it for your own use.

Think of how you want your script to operate in english first. How would you discribe what your script does? Give a numbered list, of every action and reactiont hat should take place.

IE. This is for a one-join script

1: Check to see if the joining party is know by me. If so, and he has the the +D channel flag, ont he channle he has joined, move to step 2, otherwise quit.

2: Send message to joining person.

3: Check if he has any notes. If yes, move to step 4, otherwise quit.

4: Tell the person how many notes they have and exit

This could be created (using fiction commands in some cases) like so. If you read the two of them side-by-side, you will note how much alike the code and english rules are.

Code: Select all

proc on:join {nick uh hand channel} {
  if {[matchatrr $hand +D $channel]} {
    puthelp "PRIVMSG $channel :Welcome $nick"
  } else {
    return
  }
  if {[UserHasNotes $hand]} {
    puthelp "NOTICE $nick :You have [NumberOfNotes $hand] waiting"
  }
}
Locked