Re: empty list
- From: "Niv (KP)" <kev.parsons@xxxxxxxxxx>
- Date: 6 Apr 2006 01:43:19 -0700
Niv (KP) wrote:
Hi peeps,
I have a script with a function called "get_list" which fills a list
with names,
and ends when a blank or fullstop are entered.
However, sometimes the list needs to be empty, but the whole script
falls over
when I try this.
How do I handle a null list please?
First thoughts are to force the list with an entry, like "empty_list"
then the first pass
changes the first entry & subsequent passes use the lappend.
Then, when I use the list, if it is only "empty_list" I escape the
process(s) that uses the list.
But I'm sure there's a better way.
Function below:
#----------------------------------------------------------------------------------
proc get_list {prompt} {
# set mylist empty_list
while 1 {
puts -nonewline $prompt
flush stdout
gets stdin module
set module [string trim $module]
set module [string toupper $module]
if {$module == "." || $module == ""} break
# Validate the module name is between 3 & 10 chars long
# reject if it is outside these limits.
user_pause {1}
lappend mylist $module
}
return $mylist
}
#----------------------------------------------------------------------------------
Thanks for help in the past, Kev P.
OK, fixed it myself by just adding the following:
set mylist [list]
how easy was that!
.
- Follow-Ups:
- Re: empty list
- From: slebetman@xxxxxxxxx
- Re: empty list
- From: SM Ryan
- Re: empty list
- References:
- empty list
- From: Niv (KP)
- empty list
- Prev by Date: empty list
- Next by Date: splitting script execution
- Previous by thread: empty list
- Next by thread: Re: empty list
- Index(es):
Relevant Pages
|