Marc Chantreux schrieb:
> hello guys,
> 
> i want each lines of the output of a shell command to become a key of a
> dict. I wote this code: 
> 
> let t = {}
> for k in split( system("echo foo; echo bar "), '\n' )
>     let t[k] = 1 
> endfor
> 
> but i don't like it: as the loop is here to populate the dictionnary, i
> would like to use something more appropriate. In perl for exemple, the
> map function enables you to write
> 
> my %a = map { $_ => 1 } split /\n/, qx< echo foo; echo bar>
> 
> vim has the equivalent of $_: it's called v:val, so i tried to use map
> or filter with attempts looking like that: 
> 
> let t = map( split( system("echo foo; echo bar "), '\n' ), { v:val : 1 } )
> 
> and yet i just wonder if it's possible.
> 
> regards, 
> marc 

It is possible, the second argument to map() must be a string:
    :h map()
    :let t = map(["foo", "bar"], '{v:val : 1}')

-- 
Andy

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to