Re: foreach routine

new topic     » goto parent     » topic index » view thread      » older message » newer message

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.

  res = value( "59" )

The value() function always returns a 2-element sequence. The first element is
the success/failure code and the second is the converted number. So in this case,
value() returns {0,59} where the leading 0 indicates successful conversion
occured. So in code ...

object result
result = getenv("CONTENT_LENGTH")
if sequence(result) then 
   -- a string was returned.
   result = value(result)
   if result[1] = 0 then
       --- a good conversion.
       readsize = result[2]
   else
       --- bad data in string!
   end if
else
   --- CONTENT_LENGTH doesn't exist
end if


 
> The above of course does not apply to method=GET, because in the latter, all
> the data is stuffed in the ENV. VAR. QUERY_STRING. Here we can check to see
> if getenv("QUERY_STRING") returns an atom i.e -1, because QUERY_STRING will
> either contain a string, or will be undefined. 
> --
> duke


-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu