Hi,
Ingo Karkat wrote:
> On 12-Aug-2010 10:19, winterTTr wrote:
>>
>> Or is there an alternate method to accessing dictionary when the key
>> is not found
>> , instead of showing error directly?
>
> You can use
> echo get(foo, 'var', MyFunction('var'))
>
> MyFunction() can then return whatever you want if the key 'var' is not found
> in
> foo. The only downside is that MyFunction() is always evaluated, even if the
> key
> _is_ found.
echo has_key(foo, 'var') ? foo.var : MyFunction('var')
or
echo has_key(foo, 'var') ? foo{'var'} : MyFunction('var')
will execute MyFunction() only if 'var' is not found.
Regards,
Jürgen
--
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us. (Calvin)
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php