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.

last 5 topic

Old posts that have not been replied to for several years.
Locked
a
agoni

Post by agoni »

Hi !

I would like to do a stats tcl

is there a way to save last 5 topic ? well i mean i know how to save topics on a file. But how to ask bot to replace a special line like when 5 topic are saved on the file bot will replace the topic#1 by the topic#6 .... replace topic#2 by topic#7 ..etc understand ? :-/

not my first language sorry :eek:) if someone know a TCL that use something like that let me know thx!
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

It would be more simple, to read in each line from the file into a list, remove the first item in the list and append a new item to the end. The list can then be saved to file, rather than make some hardworking script to replace items.

Code: Select all

proc file_item_shift {filename newitem} {
  set fp [open $filename r]
  set r [split [read $fp] "n"]
  close $fp
  set r [lreplace $r 0 0]
  lappend r $newitem
  set fp [open $filename w]
  foreach _A $r {
    puts $fp "$_A"
  }
  close $fp
}
Not tested, but should work. Should realy make a backup copy of the file as well, to save some heartache later on.
Locked