Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Possible bug in split() in awk95

Status
Not open for further replies.

d0vgan

Programmer
Jul 30, 2007
4
UA
Hello, everybody.

Does anybody use awk95 by Brian W. Kernighan? I think, I found a bug in realization of function split(), but I am not sure.
Here is a sample code where you can see it:

BEGIN {
time = "10:30:00,000"
split( time, a, ":" )
print a[3] # prints 00,000 - it's OK
i = split ( a[3], a, "," ) # I want to split "00,000" by ","
print i # prints 2 - it's OK
print "a[1] = " a[1] # prints garbage, must be 00
print "a[2] = " a[2] # prints garbage, must be 000
}

Regards,
Vitaliy.
 
Hi

Well, I have [tt]awk95[/tt], but on Windows I prefer to use [tt]gawk[/tt]...

Indeed, the error you described appears. I would not use the same array [tt]a[/tt] for both source and destination. Then that problem does not appear.

Better install CygWin and use a [tt]gawk[/tt], the GNU implementation of [tt]awk[/tt] compiled into native Windows executable.

Feherke.
 
The problem is here:
i = split ( [!]a[/!][3], [!]a[/!], "," )

I confirm that gawk handles this situation pretty well, but legacy awk (even nawk) don't.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Anyway, I insist on the poor programming way followed by the OP ...
I personally don't see any bug here.
 
PHV, you wrote:
> I personally don't see any bug here.

Well, if such action as split(a[3], a, ",") is incorrect, then there must be some warning from AWK, for example: "WARNING: you can not split an array element into the same array".
But awk95 silently returns correct number of subfields and corrupted data in the subfields. It is a data loss which seems to be a real bug.

Talking about awk95 and mawk, I think that awk95 has a big advantage: though mawk is faster, mawk does not support 64-bit integers. awk95 automatically switches from 32-bit integer to 64-bit integer when it's neccesary - and it is very important for calculations with large integer numbers or working with databases with high indexes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top