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
Stepan Kasal wrote:
> Kenny McCormack wrote: 
GAWK?
>
> In a following post, Kenny posted an implementation, featuring:
> 
>
> well, this has the usual limitations:
> 1) you cannot use static RE (delimited by slashes) as parameter
> 	(we are discussing non-Thompson awk, of course)
> 2) when you run match on substring, you change semantics of ^,
>       \<, \>, etc.
>
> Problem 1) is worked around by using ``dynamic RE's'' a.k.a.
> backslash hell.
> The 2) cennot be worked around, it simply makes the ``general''
> functions less general.

I think I've found a workaround for 2).

[Remove "." at beginning of each line.]

.function extract(s,re) {
.        match(s,re)
.        return substr(s,RSTART,RLENGTH)
.        }
.
.# Only works if string doesn't contain ASCII 1.
.function splitp(s,A,re,        mark,_mark )
.{ delete A
.  mark = sprintf( "%c", 1 )
.  _mark = "[^" mark "]"
.  gsub( re, mark "&" mark, s  )
.  gsub( "^" _mark "*" mark "|" mark _mark "*$", "", s )
.  return split( s, A, mark _mark "*" mark )
.}
.
.BEGIN{
.  $0 = "QuiribusX is FooBar fooBar Boom!"
.  print "Result:",n = splitp( $0, A, "\\<[A-Z][a-z]*" )
.  for (i=1; i<=n; i++) print i,"|"A[i]"|"
.
.  $0 = "foo  @   bar @ biz@boo  @ foo   bye"
.  print "Result:",n = splitp( $0, A, "^foo| +@ +" )
.  for (i=1; i<=n; i++) print i,"|"A[i]"|"
.}


Result: 3
1 |Quiribus|
2 |Foo|
3 |Boom|
Result: 4
1 |foo|
2 |  @   |
3 | @ |
4 |  @ |


Report this thread to moderator Post Follow-up to this message
Old Post
William James
12-24-04 01:55 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 08:39 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.