David, thank you.

Below is a minor modification of your code, which now fills in an
array instead of using stdout:
----cut-here----
function members
{
        typeset nval
        typeset -r IFS=$'\n'
        nameref var=$1
        nameref out=$2
        
        typeset -a out

        for nval in $(print -v var) ;  do
                case "$nval" in
                        $'\t\t'*)
                                ;;
                        *=*)
                                nval="${nval%%=*}"
                                out+=( "${nval##*[$' \t']}" )
                                ;;
                esac
        done
        return 0
}

compound x=(
        a=1
        typeset -a ar=( 8 9 10 )
        b=2
        integer b_i=2
        i="bello=hello cello=music ("
        b='typeset s="hello"'
        b_newline=$'typeset\ns="hello"'
        j=fish
        compound c=(
                typeset -a ar=( 1 2 3 )
                d=6
                e=9
        )
)

members x out_ar
print -v out_ar
----cut-here----

Olga

On Tue, Mar 22, 2011 at 8:50 PM, David Korn <[email protected]> wrote:
> cc:  [email protected]
> Subject: Re: Re: [ast-users] Enumerate member variable names in compound 
> variable?
> --------
>
>> David, your example doesn't work for nested compound variables, i.e.
>> 'compound x=( a=1 b=2 c=3 compound d=( a=1 b=2 compund z=( y=3 )) )'.
>> I tried it myself and did not found a simple way to extract just the
>> names of the members of the top level and not any level below.
>>
>> Olga
>>
>
> The following function should output only the top level.
> =====================cut here===============================
> function members
> {
>        typeset nval IFS=$'\n' blank=$' \t'
>        nameref var=$1
>        for nval in $(print -v var)
>        do      case $nval in
>                $'\t\t'*)       ;;
>                *=*)    nval=${nval%%=*}
>                        print "${nval##*[$blank]}";;
>                esac
>        done
> }
> =====================cut here===============================
>
> David Korn
> [email protected]
>



-- 
      ,   _                                    _   ,
     { \/`o;====-    Olga Kryzhanovska   -====;o`\/ }
.----'-/`-/     [email protected]   \-`\-'----.
 `'-..-| /       http://twitter.com/fleyta     \ |-..-'`
      /\/\     Solaris/BSD//C/C++ programmer   /\/\
      `--`                                      `--`
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to