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
Either put up or shut up. (I believe this is a very usefulness of this
function is self-evident - specification of table can be defined at
beginning by only specifying the delimiter strings.)

Here's my version,  "matchCol(s, r, bA)", where s is the source line, r is
regexp spefying delimiter b/w columns; bA[1..] is resultant array of
columns.

--------------

function matchCol(s, r, bA) {
bL=0
if (match(s, r)) {if (RSTART!=1) bA[++bL]= 1}
else bA[++bL]= 1
bL= matchCol2(s, r, bA, 0, bL)
if (bA[bL-1]>bA[bL]) bL-= 2 # if end is regexp
return bL
}

function matchCol2(s, r, bA, posn, bL) {
print "incoming s=" s", bL="bL", bA[bL]="bA[bL]
if (match(s, r)) {
if (bL) bA[++bL]= posn+RSTART-1       # before current regexp
if (bA[bL]+1==bA[bL-1]) bL-= 2    # if regexp is same as last
bA[++bL]= posn+RSTART+RLENGTH         # after current regexp
bL= matchCol2(substr(s, RSTART+RLENGTH), r, bA, bA[bL]-1, bL)
}
else bA[++bL]= posn+length(s)      # before last regexp
return bL
}



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


Re: awk challenge
A Ferenstein <epaalx@hotmail.com> wrote:
> Either put up or shut up. (I believe this is a very usefulness of this
> function is self-evident - specification of table can be defined at
> beginning by only specifying the delimiter strings.)
>
> Here's my version,  "matchCol(s, r, bA)", where s is the source line, r is
> regexp spefying delimiter b/w columns; bA[1..] is resultant array of
> columns.
>
> --------------
>
> function matchCol(s, r, bA) {
>  bL=0
>  if (match(s, r)) {if (RSTART!=1) bA[++bL]= 1}
>  else bA[++bL]= 1
>  bL= matchCol2(s, r, bA, 0, bL)
>  if (bA[bL-1]>bA[bL]) bL-= 2 # if end is regexp
>  return bL
> }
>
> function matchCol2(s, r, bA, posn, bL) {
>  print "incoming s=" s", bL="bL", bA[bL]="bA[bL]
>  if (match(s, r)) {
>   if (bL) bA[++bL]= posn+RSTART-1       # before current regexp
>   if (bA[bL]+1==bA[bL-1]) bL-= 2    # if regexp is same as last
>   bA[++bL]= posn+RSTART+RLENGTH         # after current regexp
>   bL= matchCol2(substr(s, RSTART+RLENGTH), r, bA, bA[bL]-1, bL)
>  }
>  else bA[++bL]= posn+length(s)      # before last regexp
>  return bL
> }

What does this supposed to do?  Your solution doesn't match example you
posted.  The count is wrong.  Repost.

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


Sponsored Links




Last Thread Next Thread Next
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:01 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.