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

Re: Memory leak when working with undefined associative array keys & problems with unset



On Sep 23,  6:59pm, Peter Stephenson wrote:
}
} Can we really not do something like the patch below?

The point of my later "naughty bit" remark was that we'd have to do
something exactly like that patch, so, yeah.

} > } $ unset "a[$key]"
} > } unset: a[hello * [ world]: invalid parameter name
} > 
} > Hmm, when examining ${a[$key]} we enter parse_subscript() with $key
} > tokenized, but there's no way to get the tokenized string to reach
} > the same point in the unset builtin
} 
} I gave up on this ages ago, frankly.  We certainly a need way of raw key
} reference, but I don't think we've got one, and each time we tweak it we
} seem to make it even more tortuous.

The basic problem is that a[$key]=foo is parsed in assignment context,
but unset a[$key] is parsed in ordinary word context.  I don't see any
way around this other than either making unset a keyword, or adding a
command-line option to unset as Daniel suggested.  Neither of these
alternatives makes me very happy.

As noted, ksh93 has (had?) also thrown up its hands on this one.

} Possibly we need yet another flag
} to say "FOR ****'S SAKE DON'T TRY TO BE CLEVER NO I MEAN IT ****" (but
} without the Tarantino script edit).

I can't think of anywhere to attach such a flag.



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