Re: CGI.pm

[prev] [thread] [next] [lurker] [Date index for 2006/06/28]

From: peter (Peter da Silva)
Subject: Re: CGI.pm
Date: 03:08 on 28 Jun 2006
> There's no language-level support for such use. The arrow is just
> a special-cased comma -- it doesn't create pairs or anything like
> that. (I'm not sure how your example gets parsed as it should,
> either.)

It's easy in a language that's a piquant blend of lisp, awk, and grep.

  proc input {type name value args} {
    eval [list tag input type $type name $name value $value] $args
  }

And of course...

  proc tag {tag args} {
    lappend list $tag
    foreach {name value} $args {
      if {"$name" == "-flag"} {
        lappend list [string toupper $value]
      } else {
        lappend list [string toupper $name]=[quote_string $value]
      }
    }
    return <[join $list " "]>
  }

And to be complete (sorry for the double negative in the first line):

  proc quote_string {string} {
    if ![string match "*[^a-zA-Z0-9.-]*"] {
      return $string
    }
    if ![string match "*'*" $string] {
      return '$string'
    }
    if ![string match "*\"*" $string] {
      return "\"$string\""
    }
    regsub -all "'" $string "\\&#39;" string
    return '$string'
  }

There's stuff above here

Generated at 21:00 on 05 Jul 2006 by mariachi 0.52