Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: assoc array assignment problem.



On Sep 28,  3:04pm, Peter Stephenson wrote:
} Subject: Re: assoc array assignment problem.
}
} I discovered another problem.
} 
} foo=
} assoc[$foo]=rod
} print ${(kv)assoc}
}  rod $foo bar

The fact that you get a leading space there even when there are no quotes
around the expansion should be telling us something.  If the key were
the empty string, print would drop it and you'd get "rod $foo bar" with
no leading space.  The key for the "rod" value in the $assoc hash table
is "\233" (meta-escape).

Now, the "\233" is coming from singsub(&s) where s = "$foo" at line 863
in getarg().  So perhaps the following will take care of it; I've tried
a few tests and didn't find anything that it breaks, but maybe someone
else will discover a reason this needs to be more complicated.

Index: Src/params.c
===================================================================
@@ -869,6 +869,7 @@
 		ht = newparamtable(17, v->pm->nam);
 		v->pm->sets.hfn(v->pm, ht);
 	    }
+	    untokenize(s);
 	    if (!(v->pm = (Param) ht->getnode(ht, s))) {
 		HashTable tht = paramtab;
 		paramtab = ht;


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author