cc:  [email protected]  [EMAIL PROTECTED]
Subject: Re: Re: [ast-developers] Two array assignment problems
--------

> > 
> >> 1. The assignment
> >>
> >>      typeset -a x=(a b c)
> >>
> >> makes an indexed array x, but a subsequent
> >>
> >>      x=([0]=a [2]=b [5]=c)
> >>
> >> turnes x into an associative array - against my declared will, and for no 
> >> obvious reason. On the other hand, the statement
> >>
> >>      typeset -a x=([0]=a [2]=b [5]=c)
> >>
> >> creates an indexed array, though the right side has exactly the same form 
> >> as above. This looks inconsistent to me, and also causes problems when 
> >> assigning values to elements of a global array in a function. Example:
> > Actually, the array  assignment should unset the variable before
> > the assignment so that x should be an associative array and have only
> > three elements.
> >      x+=([0]=a [2]=b [5]=c)
> > should modify/add elements to the indexed array.  However, there is
> > a bug here and the array is being converted to an associative array.
> > I will fix this and in the case you describe, I will first unset the
> > variable x before the assignment.
> 
> Hm, just to make things clear: I'm writing a 'function vared' which allows 
> editing of variables of any kind. It uses an editor and a temporary file, 
> which is sourced after editing. So
> 
>      typeset -a x=([1]=a [3]=b)
>      vared a
> 
> generates a line like
> 
>      x=([1]=a [3]=b)
> 
> in the file, which the user may change at his will, e.g.
> 
>      x=([1]=a [5]=c)
> 
> Do I understand you right that this would make x associative again, but the 
> following would work?
> 
>      x+=([1]=a [5]=c) 
No, this won't work.  x=() creates an empty compound variable not an
indexed array so that this will be turned into an associative array.

        typeset -a x
        x+=(([1]=a [5]=c)
Using += will leave the array type alone but will add or replace elements.
If you want to remove all the elements but leave the array type, then you can
do:
        for i in "[EMAIL PROTECTED]"
        do      unset x[$i]}
        done
If you do
        unset x
then the array type will be lost.

> 
> Regards,
> Bernd
> 
> -- 
> Bernd Eggink
> [EMAIL PROTECTED]
> http://sudrala.de
> 

David Korn
[EMAIL PROTECTED]
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to