[nycphp-talk] Any PHP users here also know TCL?
james at surgam.net
james at surgam.net
Sat Jun 7 14:14:32 EDT 2003
"soazine at pop.erols.com" says:
> I could use a hand with a TCL-related problem I'm having on my site!
>
> I have a list as follows:
>
> id 1 pollID 1 question {How are you?} answerID 1 answer {I'm fine,
> thanx}
> id 2 pollID 1 question {How are you?} answerID 2 answer {OK} id 3
> pollID 1
> question {How are you?} answerID 3 answer {Leave me alone, life
> sucks!} id
> 4 pollID 2 question {Do you think there should be a TCL
> certification exam
> in Brainbench?} answerID 1 answer {Yes} id 5 pollID 2 question {Do
> you
> think there should be a TCL certification exam in Brainbench?}
> answerID 2
> answer {No}
>
>
> I am going to edit this list by doing a change to a part of the
> question/answer set in, say, pollID 2. I want to them go to the
> first
> instance of "pollID 2" and not have to loop as this list can become
> extremely large (on my live site the XML file that this list is
> derived
> from has an id range that goes to 1000!).
>
> How then do I use [lsearch] based on this pattern? "pollID $pollID"?
> [lsearch] fails every combination I tried (returns -1), while
> [string
> first] finds it, however, the index is completely wrong for the list
> functions.
>
> Advice?
Your problem is that pollID and 2 are each elements of your list. If
you want them to be treated as one element, you need to quote them.
lsearch only searches individual elements. If you want to find the
particular element of the list that precedes the numeral "2", you'll
have to loop over the elements. Perhaps you would be better off
quoting the two strings to create one element, e.g. "pollID 2", when
you create the list, instead of when you search it.
More information about the talk
mailing list