2011/3/22 ольга крыжановская <[email protected]>:
> 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
> }
[snip]

There's still a problem with this approach:
The use of $ print -v compound_var # does not scale well if
"compound_var" contains lots of data (e.g. 500MB of (nested) variable
tree data) - each time we use $ print -v ... # the whole variable tree
is converted to a string - including the data while we only want the
names of the toplevel compound variable members.

It turns out that there is a much simpler solution using the ${!var*} operator:
-- snip --
$ ksh -c 'compound c=( typeset -a ar=( 4 5 6 [9]=8 ) ; compound cc=(
b=1 ) ) ; printf "%q\n" ${!c.*}'
c.ar
c.cc
c.cc.b
-- snip --
This still prints all sub-variables but at least avoids printing the
values. I'll post a more complete example if I find time later
today...

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) [email protected]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)

_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to