> if your hashes are nested, so you have a double-dereferencing.
> Something like
>
>
> :%s/TSWK1\|TSWK2\|TSWK3/\=s:hash[submatch(0)]/g
>
>
> or, if you have a bunch of keys, you might be able to do something like
>
>
> :let @/=join(keys(s:hash), '\|')
> :%s//\=s:hash[submatch[0]]/g
>
>
> (you might have to escape the keys if there are funky regexp
> metacharacter values in the hash keys)
I think your first idea was the best even if I don't understand how it
works and so can help to my pb.
Sum up :
A - I read some data and building structure to stored them.
-------------------------------------------------------------------------------------
let myHash= {}
let g:cnt = 1
g/patternOfReadline/=call myStoredFunc(submatch(0),..........submatch
(dataN))
func! myStoredFunc()
let myHash[g:cnt]= {'data1':a:data1,'data2':a:data2 etc....
'data5':a:data5}
let g:cnt +=1
endfunc
take 10 seconds so it's nothing... well
B - Using the stored data to generate xml data
-------------------------------------------------------------------------------------
B1 - by for on key of my hash => 35 seconds
let lineToChange = '<xmltag attr="DATA1_TO_CHANGE"
attr="DATA2_TO_CHANGE" attr="DATA1_TO_CHANGE" attr="DATA4_TO_CHANGE"/
>'
for key in keys(myHash)
let newline = substitute(lineToChange, "DATA1_TO_CHANGE", myHash
[key].data1,"g")
let newline .= substitute(lineToChange, "DATA2_TO_CHANGE", myHash
[key].data2,"")
let newline .= substitute(lineToChange, "DATA4_TO_CHANGE", myHash
[key].data4,"")
let newcontent .= newline
endfor
exec 'norm O' . newContent
====> 35 seconds
B2 - by map and join
Instead of hash of Dict I have 4 List (as many as fields of the old
Dict) and then :
let lineToChange = '<xmltag attr="DATA1_TO_CHANGE"
attr="DATA2_TO_CHANGE" attr="DATA1_TO_CHANGE" attr="DATA4_TO_CHANGE"/
>'
let List= map(copy(myList_data1), '"<xmltag attr=\"" . v:val . " attr=
\". myList_data2[v:key]. "\" attr=\"" . v:val etc...............""
',)
let newContent = join(List,'')
exec 'norm O' . newContent
====> 50 seconds
If I do as many map as that I have concat to do , 50 * N of
concat
Can you explain again you method please ?
:let @/=join(keys(s:hash), '\|')
> :%s//\=s:hash[submatch[0]]/g
--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment