Re: foreach routine
- Posted by duke normandin <dnormandin at bsdrocksperlrolls.com> Dec 23, 2006
- 645 views
Derek Parnell wrote: > > duke normandin wrote: > > > > Chris Bensler wrote: > > > The getenv() routine will return -1 if the environment variable > > > CONTENT_LENGTH > > > doesn't exist. If it does exist, a string will be returned. > > > > Are you sure? I've never proven this to myself, but it has always been my > > understanding that with respect the method=POST, the ENV. VAR. > > CONTENT_LENGTH > > would be set to the amount of bytes sent out. THEREFORE, this is why we > > "read" > > that many bytes from STDIN, and only that many. So my point is that > > CONTENT_LENGTH > > will in one case be a positive number or a -1 -- both atoms. No? > > Yes and no. The Euphoria function getenv() always returns a string if the > environment > variable exists, and -1 if it doesn't exist. In your case, CONTENT_LENGTH will > most likely always be there due to the CGI environment, but when getenv() > returns > its content, it is a string representation of a number and not the number > itself. > So if the number of characters to read in from STDIN is 59, > getenv("CONTENT_LENGTH") > will return "59" and not 59. Thus you have to convert the string "59" to its > number form. I got it! Damn! I've got to watch the data types more carefully. Not used to it. ;) To recap, getenv returns the atom -1 if the ENV.VAR. is unset OR a string containing whatever. In the case of CONTENT_LENGTH I was expecting an integer. I now know to convert CONTENT_LENGTH *to* an integer. > res = value( "59" ) [snip] I really don't need to do all that testing. What the Perl/PHP etc world has done all this time is: 1. getenv("REQUEST_METHOD") 2. if == "POST" 2.a value_array = value(getenv("CONTENT_LENGTH") 2.b stash get_bytes(0, value_array[2]) 3. if == "GET" 3.a stash getenv("QUERY_STRING") 4. if == "some_bogus_method" 4.a cgi_die("gracefully") 5. amen That is what I want to reproduce in Euphoria come "hell or high water" ;) Once I have the above "stash", then we use your "foreach" and "split" code to massage the FORM[key]=values I love it !! Thanks you all for the mini EU tutorials!! -- duke