[erlang-questions] YAWS queryvar for empty variables

Steve Vinoski vinoski@REDACTED
Wed Feb 4 05:12:14 CET 2009


On 2/3/09, Vik Olliver <vik@REDACTED> wrote:
> If a URL with args like:
>
>  http://.../...&foo=sometext&bar=
>
>  is passed to queryvar/2, how do I determine that the variable "bar" has
>  been defined and contains an empty list, as opposed to the non-existent
>  variable "cow" that hasn't been defined at all?

Given an #arg record named Arg (as in
<http://yaws.hyber.org/arg.yaws>), just do this:

case lists:keysearch("bar", 1, yaws_api:parse_query(Arg)) of
    {value, {"bar", Bar}} ->
       bar_is_present;
    false ->
       bar_is_not_present
end.

If "bar" is present in the query portion of the URI like in the
example you've shown, you'll hit the first case and the value of Bar
will be the atom undefined. If you instead searched for "cow", which
is not present in the URI, it would hit the false case.

--steve



More information about the erlang-questions mailing list