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.

replacing line problem

Old posts that have not been replied to for several years.
Locked
c
collett9
Voice
Posts: 11
Joined: Mon Dec 15, 2003 11:38 pm

replacing line problem

Post by collett9 »

Well after my last post and getting that to work, it turned out not to be what I needed exactly.


I need to REPLACE the line, so I did a bit of searching and found:

http://forum.egghelp.org/viewtopic.php?p=27613#27613

Here is what I have, and it's not working:

Code: Select all

bind pub - !setvar replaceLines
bind pub - !setvar cmd:setvar

proc replaceLines {args} { 
   if {[llength $args]>=3} { 
      foreach {file start end} $args break 
      set cmd [list lreplace [split [read [set f [open $file r]]] \n] $start $end] 
      close $f 
      if {[llength $args]>3} {lappend cmd [lindex $args 3]} 
      puts -nonewline [set f [open $file w]] [join [eval $cmd] \n] 
      close $f 
   } { 
      error "wrong # args: should be \"[lindex [info level 0] 0] file start end ?replacement?\"" 
   } 
} 

proc cmd:setvar {nick host handle chan text} { 
global privchan variwannaset
 foreach channel $privchan {
   if {$chan == "$privchan"} {
   set variwannaset "$text"
   replaceLines vars.tcl 76 76 [set variwannaset "$text"]
   putquick "NOTICE $nick :Variable has been set to: \002$variwannaset\002"
   }
 }
}
(As you can tell, the line I want to edit is 76)

Help? :roll:
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

The script you found seems to remove line 76 and add another one onto the very end. You want to replace 76? Change the lreplace command to add the new line in place of the one you remove. See the tcl manual http://www.tcl.tk/man/tcl8.4/TclCmd/contents.htm for the lreplace command for details.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

I think this is what you want...

Code: Select all

replaceLines vars.tcl 76 76 [list set variwannaset "$text"]
Have you ever read "The Manual"?
c
collett9
Voice
Posts: 11
Joined: Mon Dec 15, 2003 11:38 pm

Post by collett9 »

yea, that's what I needed, however it poses yet another problem

in the file it actually sets it as:

Code: Select all

set variwannaset text


instead of what I NEED it to be

Code: Select all

set variwannaset "text"

I've also tried the

Code: Select all

[list set variwannaset "\"$text\""]
and every combination I possibly know...

:(
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

As I told you on irc, no, you don't NEED it to be "text", because in Tcl,
set var word , is the same as set var "word" ...
If it is a multi-word, the list command will make it set var {word1 word2}, which is essentially the same as set var "word1 word2", less variable substitution, which your original line will take care of anyway...
Locked