Reply to Re: TCL/PHP/XML problem: I need to convert an XML file into a TCL list

Your name:

Reply:


Posted by comp.lang.tcl on 11/25/06 18:53

Bryan Oakley wrote:
> comp.lang.tcl wrote:
> > Bryan Oakley wrote:
> >
> >>comp.lang.tcl wrote:
> >>
> >>> set cannotRunPHP [catch {exec "echo '$php' | php" >@stdout
> >>>2>&stderr} errorMsg]
> >>
> >>You need to re-read the man page on exec. The first argument to exec is
> >>a filename that will be exec'd; it is not a command line. If you want to
> >> run a command line you should exec a command line processor (/bin/sh,
> >>command.com, whatever).
> >>
> >>Since "php" is what you want to exec, and $php is what you want to send
> >>to its stdin, use "<<" (documented on the exec man page):
> >>
> >> if {[catch {exec php << $php} result]} {
> >> puts "error exec'ing php: $resulut"
> >> } else {
> >> puts "php result: $result"
> >> }
> >
> >
> >
> > Now I get this error:
> >
> > couldn't execute "php": no such file or directory
> >
> > When I try this:
> >
> > [TCL]
> > set cannotRunPHP [catch {exec exec php << $php >@stdout 2>&stderr}
> > errorMsg]
> > if {$cannotRunPHP} {
> > puts $errorMsg
> > return {}
> > } else {
> > if {![IS_LIST $contentsList]} { set contentsList [split
> > $contentsList] }
> > if {[llength $contentsList] == 0} { lappend contentsList {?} }
> > return [lrange $contentsList [expr {[lsearch -exact $contentsList
> > "?"] + 1}] end]
> > }
> >
> > [/TCL]
> >
> > Wow this should only take an hour, it's taken 3 days so far!
>
> When you are learning a new language, it always takes much longer to
> solve problems. And in your case I'm afraid, you aren't taking much time
> to actually learn the language which is compounding the problem.
>
> The answer to your current problem is well documented in the exec man
> page, and on the exec pages on the tcler's wiki. The problem you are
> encountering is very simple: you are telling it to execute "php" but tcl
> can't find "php". The short answer is, you either have to explicitly
> tell the exec command which *file* to execute (eg: exec
> /usr/local/bin/php), or you have to make sure that the file you tell it
> exists somewhere within a directory defined in your PATH environment
> variable.
>
> Phil, I'm sorry you're having so many problems. You are correct that
> this probably should have taken only an hour or two for a seasoned
> programmer, but you are not a seasoned programmer and properly parsing
> XML is, generally speaking, a Hard Problem. At least, it's hard when you
> choose to not use proper XML parsing solutions and instead rely on a
> series of text transformations.
>

Bryan, you're going to die when you hear this: I have 9+ years web
development experience, been doing TCL for about 7 years (mostly via
Vignette), have 5 certifications including a master PHP certification..
and I have no clue how to do any of this. Thus I am a seasoned
programmer (though honestly nobody here will ever recognize or believe
that)


> Tcl is a very powerful language, but it doesn't have built-in facilities
> to parse XML. This is not a weakness of Tcl, it's just the way it is.
> The beauty of Tcl is, people can write extensions to the language to do
> just about anything, including parsing XML. Unfortunately, you are
> choosing not to take the time to learn how to use them.

I've said this over and over again: it's not that I won't take the
time, it's that I CANNOT do it because I have a learning disability
called Attention Deficit Disorder which psychologically does not permit
me to take the time to learn it. I am unable to understand man pages
like you and Cameron and other can do in your sleep. I read the Tcl
extensions online but don't understand them. The pages are in
Hungarian to me. I can't fathom them, I don't know how to install
them, manipulate them, use them, anything. If people could show me a
very very simple way of parsing this:

<?xml version="1.0" encoding="utf-8" ?><trivia><entry id="1101"
triviaID="233" question="Who wrote &quot;Trilogy of Knowledge&quot;?"
answerID="1" correctAnswerID="1" answer="Believer"
expDate="1139634000"></entry><entry id="1102" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="2"
correctAnswerID="1" answer="Saviour Machine"
expDate="1139634000"></entry><entry id="1103" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="3"
correctAnswerID="1" answer="Seventh Avenue"
expDate="1139634000"></entry><entry id="1104" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="4"
correctAnswerID="1" answer="Inevitable End"
expDate="1139634000"></entry><entry id="1105" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="5"
correctAnswerID="1" answer="No such song existed"
expDate="1139634000"></entry></trivia>

Into this:

id 1101 triviaID 233 question {Who wrote &quot;Trilogy of
Knowledge&quot;?} answerID 1 correctAnswerID 1 answer Believer expDate
113963500

[etc]

Then that would do it, but I guess the problem is that I can't explain
my problem, nor my disabilities, well enough for the programming
community to fathom my dilemma.

Phil

>
> I'll again recommend trying the xml2list function documented here:
> http://mini.net/tcl/3919. I'm guessing that will work good enough for
> you. Fortunately, it appears you're working on a simply hobby
> application rather than a commercial application so we don't have to
> worry so much about robustness.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация