Thursday, December 24, 2009

Re: Dupicate and increment lines

> Goal : multiply some parts of lines which contain factors
>
> foo(2)bar(9)
>
> Should become
>
> foo1bar1
> foo1bar2
...
> foo1bar9
> foo2bar1
> foo2bar2
...
> foo2bar9
>
> I have done a func that receive (foo,2,bar,9) but it take 0.0008
> second.

Given that regardless of how the function is implemented, it will have
polynomial time characteristics, 0.0008 seconds isn't bad at all. Given
that you haven't posted the body of your function, it's a little hard to
sniff for hot-spots. If it's something you only have to perform once,
it may be best to just let it run (albeit slowly), rather than spend
hours optimizing something for a one-time run. However, if it's
something repeatable, you might already be close to optimal performance.
Otherwise, I'd write a little python (or if you're a perl/awk/ruby
programmer, use one of those) script to do the dirty work for you.

> In fact I have more than 2000 lines with this format : foo(2)bar(9)
> or other possible cases
>
> foobar
> foo(X)bar
> foobar(Y)
> foo(X)bar(Y)
>
> foo(X)bar(Y)foo(Z)
> foobar(Y)foo(Z)
> foo(X)barfoo(Z)

You haven't mentioned what to do with missing X or Y values, and haven't
detailed Z...An empty value could be interpreted as 0 or 1, and Z could
be an additional combinatoric factor. And you don't give a decent way
of recognizing the various parts...is "foobar" just one instance, or is
that "foo" followed by an implicit count, followed by a "bar"? And in
the Z lines, does it repeat the same match as before? Can there be more
than 3 number instances? Are "foo" and "bar" regular expressions or are
they constant text?

There are a lot of details you omit which makes it hard to provide a
solution. Again. You've been asked multiple times in other threads to
pose the problem in its entirety which includes expected inputs *and*
the expected outputs.

> Have you got another way to improve instead of doing
> g/\([^(]\)\((\d\+)\)....../\=myFunc(submatch(1) etc...)/

Well, again, you've not posted the actual code you're using since
submatch(n) is only available within a :s command (which you likely
intended) and not a :g command (which you typed), and your function
syntax doesn't compile, so it's hard to even guess what your function does.

Please answer all of the above questions regarding the problem
space...only then can we begin to help you. Though given that it sounds
like you have a working-but-slow solution, just use that one. Or maybe
even post its code so we have something to work from to try and infer
"correct" behavior.

I was going to hammer out a quick python script to tackle the problem,
but the problem is too ill-defined to get anywhere.

-tim


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

No comments:

Post a Comment