Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: awk challenge
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.

Report this thread to moderator Post Follow-up to this message
Old Post
William Park
11-16-04 11:50 PM


Re: awk challenge

William 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
11-16-04 11:50 PM


Re: awk challenge
In 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.


Report this thread to moderator Post Follow-up to this message
Old Post
Kenny McCormack
11-16-04 11:50 PM


Re: awk challenge

Kenny 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
11-16-04 11:50 PM


Re: awk challenge
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.

> 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.



Report this thread to moderator Post Follow-up to this message
Old Post
A Ferenstein
11-16-04 11:50 PM


Re: awk challenge
In 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).
 


Report this thread to moderator Post Follow-up to this message
Old Post
Kenny McCormack
11-16-04 11:50 PM


Re: awk challenge

Kenny 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.

> 
>
>

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
11-16-04 11:50 PM


Re: awk challenge

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.

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
11-16-04 11:50 PM


Re: awk challenge

Kenny 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
11-16-04 11:50 PM


Re: awk challenge
In 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).
 


Report this thread to moderator Post Follow-up to this message
Old Post
Kenny McCormack
11-16-04 11:50 PM


Sponsored Links




Last Thread Next Thread Next
Pages (8): [1] 2 3 4 5 6 » ... Last »
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:12 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.