comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: [Q] extracting value from a structure ...
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: [Q] extracting value from a structure ... [message #12781] Thu, 10 September 1998 00:00
Thomas A. McGlynn is currently offline  Thomas A. McGlynn
Messages: 23
Registered: March 1996
Junior Member
dEdmundson@Bigfoot.com wrote:
>
> Consider the following:
>
> r = {name: 'john', age=18}
> s = 'age'
>
> Given the string s, is there an easy way to
> extract the value of the corresponding tag
> in r? s is not known at compile time so
> the trivial r.age reference is not possible.
> My current solution is:
>
> command = 'v=r.'+s
> execute(command)
> print, 'age=',v
>
> but this is slow because of the run time
> compilation of 'command'. Surely there
> is an easier way ...
>
> Cheers,
> Darran.
>

Sure. Try something like

w = where(tag_names(r) eq strupcase(s))
if (w(0) ne -1) then print, 'age=',r.(w(0))

If you're doing this a lot you'll want to store
the tag_names array somewhere.

Regards,
Tom McGlynn
tam@silk.gsfc.nasa.gov
[Message index]
 
Read Message
Previous Topic: Re: Support for image formats
Next Topic: Re: finding array subscripts of minimum value of 3 dim. fltarr

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 10:44:53 PDT 2025

Total time taken to generate the page: 0.31835 seconds