Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Variable variable names?

0 views
Skip to first unread message

Jan Johansson

unread,
Jul 14, 2001, 6:42:41 AM7/14/01
to

Now,
set datatype mythingie
set ${datatype}_declared_at [unixtime]

works as expected, but, how do i access the data stored in the var, since
if i use

[ctime ${datatype}_declared_at] it uses the name and not the data (and
that is pretty naturally), but i dont suppose that
${${datatype}_declared_at} works?
So, how do i read my dear old unixtime from such a variable?

Thanks.

/jan

Kether

unread,
Jul 14, 2001, 8:01:35 AM7/14/01
to
Try ${{datatype}_declared_at}

Jon Guyer

unread,
Jul 14, 2001, 9:56:59 AM7/14/01
to
In article <3b5034ef...@news.iol.ie>, ba...@oceanfree.net (Kether)
wrote:

> Try ${{datatype}_declared_at}

Eh? I get "can't read "{datatype": no such variable"

What about [set ${datatype}_declared_at]

--
Jonathan E. Guyer

<http://www.his.com/jguyer/>

Bryan Oakley

unread,
Jul 14, 2001, 11:05:12 AM7/14/01
to

"Jan Johansson" <j...@mupp.net> wrote in message
news:Pine.LNX.4.10.101071...@animal.mupp.net...

>
> Now,
> set datatype mythingie
> set ${datatype}_declared_at [unixtime]

An easier way to accomplish this is by using an array:

set declared_at($datatype) [unixtime]

To answer the specific question it's important to remember (or learn...)
that the set command has two forms -- one to set a value and one to retrieve
a value. So, the idiomatic way to do what you want is this:

set ${datatype}_declared_at

The ${datatype} will be evaluated and converted to "mythingie" before being
passed to the set command. The set command will thus see
"mythingie_declared_at", consider that the name of a variable, and fetch the
value of that variable.


TaKeDa

unread,
Jul 14, 2001, 2:34:48 PM7/14/01
to
"Jan Johansson" <j...@mupp.net> wrote in message
news:Pine.LNX.4.10.101071...@animal.mupp.net...

I don't know it is a best way, but you can use:
[set ${datatype}_declared_at]

This should return value which you want get... (set without second argumet,
just returns value in variable)
Anyway, I think is better to use array for this kind of stuff.

Best regards,
TaKeDa

Phil Powell

unread,
Jul 14, 2001, 2:42:34 PM7/14/01
to
Try using this:

[ctime [set ${datatype}_declared_at[unixtime]]]

This provided there is a value within this var-within-var

Phil

"Jan Johansson" <j...@mupp.net> wrote in message
news:Pine.LNX.4.10.101071...@animal.mupp.net...
>

Jan Johansson

unread,
Jul 14, 2001, 8:39:43 PM7/14/01
to
> I don't know it is a best way, but you can use:
> [set ${datatype}_declared_at]
>
> This should return value which you want get... (set without second argumet,
> just returns value in variable)
> Anyway, I think is better to use array for this kind of stuff.


Thankyou, more people pointed out the array aproach, so i will use that..
Question do, is ther eanyway to do a test if a certain element in an array
exists? like an info exists but for elements in arraay?

Thankyou

Jan

Jan Johansson

unread,
Jul 14, 2001, 8:38:31 PM7/14/01
to
> Eh? I get "can't read "{datatype": no such variable"
>
> What about [set ${datatype}_declared_at]

Wroks, but someone else pointed out i should go with arrays, so ill do
that. But thankyou nonetheless, tyou did after all answer my question as i
had put it :)

Jan Johansson

unread,
Jul 14, 2001, 8:41:05 PM7/14/01
to
> Try using this:
>
> [ctime [set ${datatype}_declared_at[unixtime]]]
>
> This provided there is a value within this var-within-var
>
> Phil


A thankyou to yuo and all the others who helped me on thsi one :)

Jan Johansson

unread,
Jul 14, 2001, 8:36:43 PM7/14/01
to
> An easier way to accomplish this is by using an array:
>
> set declared_at($datatype) [unixtime]

Ah. much easier :) But that gives a followup question. I cant seem to be
able to use "info exists" on an element in an array, how do i check if an
element exists within an array?

Thanks

Rolf Ade

unread,
Jul 14, 2001, 11:03:42 PM7/14/01
to
In article Jan Johansson <j...@mupp.net> wrote:
>Question do, is ther eanyway to do a test if a certain element in an array
>exists? like an info exists but for elements in arraay?

Yes. 'info exists' works also for array entries.

% set foo(bar) baz
baz
% info exists foo(bar)
1
% info exists foo(boo)
0

rolf


Michael A. Cleverly

unread,
Jul 15, 2001, 12:53:32 AM7/15/01
to Jan Johansson

info exists declared_at($datatype) ;# works
info exists $declared_at($datatype) ;# doesn't work

Jan Johansson

unread,
Jul 15, 2001, 5:25:37 AM7/15/01
to
> Yes. 'info exists' works also for array entries.
>
> % set foo(bar) baz
> baz
> % info exists foo(bar)
> 1
> % info exists foo(boo)
> 0


Yes, i understand now. Thanks!

Jan Johansson

unread,
Jul 15, 2001, 5:23:55 AM7/15/01
to
> info exists declared_at($datatype) ;# works
> info exists $declared_at($datatype) ;# doesn't work


Aaaaah, i see the light! Thankyou.

0 new messages