cc: [email protected]
Subject: Re: Re: Re: [ast-users] Enumerate member variable names in compound
variable?
--------
> 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
>
Yes, this is a more efficient way and if I extend the ${!var.*} matching
to restict the matching level, it would be even more efficient.
==========================cut here======================
function members
{
typeset name
nameref var=$1
for name in ${!var.*}
do [[ $name == +([!.]).+([!.]) ]] && print ${name#*.}
done
}
==========================cut here======================
David Korn
[email protected]
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users