Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

This should be easy....right??? 1

Status
Not open for further replies.

Dineen

Programmer
Jun 20, 2001
16
0
0
US
I'm a newbie to TCL. What I am trying to do is read a URL string (ie.
If you is equial to person (i need to read up to the # ign), then i have already set up if/then's throughout my site for different things.

I use ASP a lot, so i'm just so used to
WHO = Request.Querystring(you)

I can't find anything anywhere about this and I'd hoped it was a simple task to read what's in this query string!

Thank you!
Dineen
 
Try reading up on the regexp command. You can build a query that will parse the string automagically. I would do it for you, but then you would miss out on all the fun!
 
If you're actually doing CGI programming in Tcl, you might also want to take a look at a couple of packages that simplify handling things like this. The standard Tcl distribution now includes something called The Standard Tcl Library, or tcllib, which is a collection of useful utilities including:

[ul][li]Simple CGI interaction[/li][li]FTP interaction[/li][li]POP3 interaction[/li][li]NNTP interaction[/li][li]Command-line argument parsing[/li][li]Code profiling[/li][/ul]
Recent version of Tcl include tcllib in the installation. You can download it separately from
Unfortunately, the documentation for the packages included in tcllib can be a bit sketchy, but it should be enough to get you going. (If the version of tcllib installed on your system doesn't include documentation -- as was the case with version 0.6 -- download and install the latest version from the URL given above).

To accomplish what you originally asked for above (assuming that your script is being executed as a CGI script), you can use the following code:

Code:
# Load the ncgi package
package require ncgi

# Parse the query information
ncgi::parse

# Get the value you want
set val [ncgi::value you]

A more full-featured CGI package is Don Libes' cgi_tcl. You can find out more information about it and download it from In addition to the information about the package provided there, there is a chapter about cgi_tcl in the the book Web Tcl Complete by Steve Ball. - Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Thanks all. I need to have this done in about an hour or so. It seems like it should be so simple. I'll try something else.
 
Okay, quick and dirty with regexp:

Code:
% set str {[URL unfurl="true"]www.mysite.com?you=person#blahblahblah}[/URL]
[URL unfurl="true"]www.mysite.com?you=person#blahblahblah[/URL]
% regexp {\?([^=]+)=([^#]*)} $str junk name value
1
% puts "$name: $value"
you: person

This is a direct screen capture of an interactive tclsh session, so the "%" characters are the Tcl prompts. The regular expression pattern in the regexp command stores all characters between the "?" and "=" in the variable name, and all characters between the "=" and "#" in the variable value. regexp returns 1 if it successfully matched the pattern, 0 otherwise. - Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Lifesavers you are! Thank you so much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top