Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Dynamic variable naming
Hi,
I'm having a problem doing something that I know you can do in TCL.
Let's say I have a var

set ::ns::subns::var test

I then have a proc which takes in a namespace and a sub namepsace as
its params:

proc testproc { namespace subnamespace } {
...
}

I want to print out the value 'test' if someone calls it as:

testproc { "ns" "subns" }

So I'm looking for a way to eval a variable when you don't know the
name of the variable up front.  ANy help is appreciated!


Report this thread to moderator Post Follow-up to this message
Old Post
gcgaim@gmail.com
08-24-07 09:27 AM


Re: Dynamic variable naming
Hi,

gcgaim@gmail.com wrote :
> Hi,
> I'm having a problem doing something that I know you can do in TCL.
> Let's say I have a var
>
> set ::ns::subns::var test
>
> I then have a proc which takes in a namespace and a sub namepsace as
> its params:
>
> proc testproc { namespace subnamespace } {
> ...
> }

[set varName] returns the value of variable varName. So all you have to
do is built varName from procedure arguments:

proc testproc {namespace subnamespace} {
return [set "::${nanespace}::${subnamespace}::var"]
}

Note that "return" and quotes are useless, added there only for clarity.

>
> I want to print out the value 'test' if someone calls it as:
>
> testproc { "ns" "subns" }

From prototype you gave above, someone will actually call it as:
% testproc "ns" "subns"

>
> So I'm looking for a way to eval a variable when you don't know the
> name of the variable up front.  ANy help is appreciated!
>

Eric

-----
Eric Hassold
Evolane - http://www.evolane.com/

Report this thread to moderator Post Follow-up to this message
Old Post
Eric Hassold
08-24-07 09:27 AM


Re: Dynamic variable naming
On Aug 23, 1:17 pm, Eric Hassold <hass...@evolane.com> wrote:
> Hi,
>
> gcg...@gmail.com wrote :
> 
> 
> 
> 
>
> [set varName] returns the value of variable varName. So all you have to
> do is built varName from procedure arguments:
>
> proc testproc {namespace subnamespace} {
>    return [set "::${nanespace}::${subnamespace}::var"]
>
> }
>
> Note that "return" and quotes are useless, added there only for clarity.
>
>
> 
> 
>
>  From prototype you gave above, someone will actually call it as:
> % testproc "ns" "subns"
>
>
> 
>
> Eric
>
> -----
> Eric Hassold
> Evolane -http://www.evolane.com/

Thanks :)


Report this thread to moderator Post Follow-up to this message
Old Post
gcgaim@gmail.com
08-24-07 09:27 AM


Re: Dynamic variable naming
On Aug 23, 1:17 pm, Eric Hassold <hass...@evolane.com> wrote:
> gcg...@gmail.com wrote :
 
> 
>
 


> [set varName] returns the value of variable varName. So all you have to
> do is built varName from procedure arguments:
>
> proc testproc {namespace subnamespace} {
>    return [set "::${nanespace}::${subnamespace}::var"]

note that needs to be ${namespace}, not ${nanespace}

>
> }

I started to respond with something similar, until I hit that last
nite. Maybe I'm reading way too much into that sentence. But it reads
as if the Original Poster didn't know that the value "test" was going
to be in variable "var" and s/he needed to introspectively determine
what variables were in in the subnamespace and then figure out which
one to print. There wasn't enough requirements to tell us how one
would decide which variable would be displayed - perhaps all of them?



Report this thread to moderator Post Follow-up to this message
Old Post
Larry W. Virden
08-24-07 09:27 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Tcl archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:40 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.