NYCPHP Meetup

NYPHP.org

[nycphp-talk] Any PHP users here also know TCL?

Adam Fields fields at surgam.net
Sat Jun 7 20:05:18 EDT 2003


On Sat, Jun 07, 2003 at 05:42:09PM -0400, soazine at pop.erols.com wrote:
> Thanx for your solution.  Now I have to face another issue.  The "pollID
> $pollID" elements that were joined together into one element in the same
> list now have to be broken apart within the same list.  How do I do that
> too?

I'd recommend using absolute quoting (braces) instead of double
quotes when you build your list in the first place. Braces are
technically the sub-list operator.

-------------
% set list {{id 1} {pollID 1} {question {How are you?}} {answerID 1} {answer {I'm fine, thanx}} }
{id 1} {pollID 1} {question {How are you?}} {answerID 1} {answer {I'm fine, thanx}}
% lindex $list 0
id 1
% lindex $list 1
pollID 1
% lindex [lindex $list 1] 1
1
% lrange $list 0 1
{id 1} {pollID 1}
% lindex [lrange $list 0 1] 0
id 1
-------------

Does that answer your question?


> Thanx
> Phil
> 
> Original Message:
> -----------------
> From:  james at surgam.net
> Date: Sat,  7 Jun 2003 14:14:35 -0400
> To: talk at nyphp.org
> Subject: Re: [nycphp-talk] Any PHP users here also know TCL?
> 
> 
> 
> 
> "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.
> 
> 
> 
> 
> 
> 
> --------------------------------------------------------------------
> mail2web - Check your email from the web at
> http://mail2web.com/ .
> 
> 
> 
> 
> 
> --- Unsubscribe at http://nyphp.org/list/ ---
> 
> 
> 

-- 
				- Adam

-----
Adam Fields, Managing Partner, fields at surgam.net
Surgam, Inc. is a technology consulting firm with strong background in
delivering scalable and robust enterprise web and IT applications.
http://www.adamfields.com



More information about the talk mailing list