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.
Old posts that have not been replied to for several years.
J
Jimbo
Post
by Jimbo » Fri May 24, 2002 9:22 am
Without doing gets $channel line 5 times....how can i read the 5th line of a file?
ppslim
Revered One
Posts: 3914 Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England
Post
by ppslim » Fri May 24, 2002 11:56 am
There is no way. Allthough you could create a proc that will do the the gets 5 times for you.
Code: Select all
proc get_line {file line} {
set fp [open $file r]
set r {}
while {![eof $fp]} {
set i 0
while {$i < $line} {
set r [gets $fp]
incr i
}
break
}
catch {close $fp}
return $r
}
Then you can use it like
Code: Select all
my code here
set test [get_line file.name 5]
which will get line 5
Wcc
Master
Posts: 278 Joined: Sun Oct 28, 2001 8:00 pm
Location: USA
Contact:
Post
by Wcc » Fri May 24, 2002 1:17 pm
It would make more sense to me to read the entire file with [read $channel], split it by n, then use lindex to pull lines.
Petersen
Owner
Posts: 685 Joined: Thu Sep 27, 2001 8:00 pm
Location: Blackpool, UK
Post
by Petersen » Fri May 24, 2002 2:49 pm
well, ppslim's way is cpu intensive, your way is ram intensive. which method is the best to use depends on the length of the file.
J
Jimbo
Post
by Jimbo » Fri May 24, 2002 4:52 pm
Cheers ppl...Just so ya know im using ppslim's idea cos its neater....cos im needing to get a certain line quite frequently!!!