Code Comments
Programming Forum and web based access to our favorite programming groups.A Ferenstein <epaalx@hotmail.com> wrote: > Here's the task: create an array containing beginning and end of columns ( of > some text not matching a regexp string) separated by a regexp string. > Condition: can't use substr() to read character-by-character! > > For example, let's say regexp=" " (ie. a space), result "delimiter_array" > (where x represents some character not matched by regexp): > > xxx xxxx xxxxx > > would result in > delimiter_array[1] is 1 > delimiter_array[2] is 3 > delimiter_array[3] is 6 > delimiter_array[4] is 9 > delimiter_array[5] is 11 > delimiter_array[6] is 15 You example doesn't match your numbers. Count again, and repost.
Post Follow-up to this messageWilliam Park wrote: > A Ferenstein <epaalx@hotmail.com> wrote: > > > > You example doesn't match your numbers. Count again, and repost. Or not :-). Don't know about anyone else but IMHO "let's see how clever you are" exercises are just newsgroup clutter. In that category I include anything that says "solve this without doing ABC" without a good reason for that restriction. Ed.
Post Follow-up to this messageIn article <cn08hr$llc@netnews.proxy.lucent.com>, Ed Morton <morton@lsupcaemnt.com> wrote: ... >Or not :-). Don't know about anyone else but IMHO "let's see how clever >you are" exercises are just newsgroup clutter. In that category I include >anything that says "solve this without doing ABC" without a good reason >for that restriction. You are obviously an engineer and not a mathematician. I need say no more.
Post Follow-up to this messageKenny McCormack wrote: > In article <cn08hr$llc@netnews.proxy.lucent.com>, > Ed Morton <morton@lsupcaemnt.com> wrote: > ... > > > > You are obviously an engineer and not a mathematician. He shoots, he scores. Guilty as charged. > I need say no more. A mathematician would have found a way to say "I need say no more" without using vowels. Ed.
Post Follow-up to this messageThe reason for not using substr() character-by-character is self evident (clue. 'very big line'), neither would it exploit awk's strengths - optimised functions related to strings. Plus the aim of exercise to think rather than force. Please look at my version of solution. > Or not :-). Don't know about anyone else but IMHO "let's see how clever > you are" exercises are just newsgroup clutter. In that category I > include anything that says "solve this without doing ABC" without a good > reason for that restriction.
Post Follow-up to this messageIn article <cn1qeh$m5s$1@newstree.wise.edt.ericsson.se>, A Ferenstein <epaalx@hotmail.com> wrote: >The reason for not using substr() character-by-character is self evident >(clue. 'very big line'), neither would it exploit awk's strengths - >optimised functions related to strings. Plus the aim of exercise to think >rather than force. >Please look at my version of solution. Ed has made it clear that he is a simpleton who doesn't like theoretical problems. You are unlikely to change his way of thinking (or not).
Post Follow-up to this messageKenny McCormack wrote: > In article <cn1qeh$m5s$1@newstree.wise.edt.ericsson.se>, > A Ferenstein <epaalx@hotmail.com> wrote: > The clue appears to be missing from your original posting. Had you said "I have a problem where my lines are very long and using substr() takes too long because XYZ - is there a way to optimizes this code" then we wouldn't be having this chat. neither would it exploit awk's strengths - But it does exploit awk's strengths - a rich set of component functions from which you can quickly and easily build solutions to problems. No-ones using awk vs C for it's speed of execution. Plus the aim of exercise to think I suspect most of us get a reasonable workout every day solving real problems and don't need the additional exercise. I did. It's not immediately obvious that a recursive solution with multiple calls to "match()" would be any faster than using substr(). > > Ed has made it clear that he is a simpleton who doesn't like theoretical > problems. You are unlikely to change his way of thinking (or not). Yes, exactly. Hey, hang on.... I need to go ask someone if that's an insult. Ed. > > >
Post Follow-up to this message
A Ferenstein wrote:
>
>
> Given that column separators are regexp's, match() is un-avoidable.
>
>
No it isn't:
gawk '{c=gsub("\(.\)","&"SUBSEP);FS=SUBSEP;$0=$0;idx=1;
for (i=1; i<NF; i++) {
if ($i == " ") {
if (fnd) {
delimiter_array[++idx] = i-1
idx++;
}
fnd = 0
} else {
if (!fnd) {
delimiter_array[idx] = i
}
fnd = 1
}
}
delimiter_array[++idx] = i-1
}'
I have no idea if the above is any faster or slower than using substr()
or your recusrion with match(). My only point is that there's alternatives.
Regards,
Ed.
Post Follow-up to this messageKenny McCormack wrote: > In article <cn08hr$llc@netnews.proxy.lucent.com>, > Ed Morton <morton@lsupcaemnt.com> wrote: > ... > > > > You are obviously an engineer and not a mathematician. He shoots, he scores. Guilty as charged. > I need say no more. A mathematician would have found a way to say "I need say no more" without using vowels. Ed.
Post Follow-up to this messageIn article <cn1qeh$m5s$1@newstree.wise.edt.ericsson.se>, A Ferenstein <epaalx@hotmail.com> wrote: >The reason for not using substr() character-by-character is self evident >(clue. 'very big line'), neither would it exploit awk's strengths - >optimised functions related to strings. Plus the aim of exercise to think >rather than force. >Please look at my version of solution. Ed has made it clear that he is a simpleton who doesn't like theoretical problems. You are unlikely to change his way of thinking (or not).
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.