Annihilannic
MIS
Is it just me or were A, W or K sadistic?
Trying this code in various awks gives surprising results... surprising to me anyway.
Linux gawk 3.1.0
[tt]4 four
5 five
6 six
7 seven
8 eight
0 zero
1 one
2 two
3 three[/tt]
Solaris 8 awk
[tt]2 two
3 three
4 four
5 five
6 six
7 seven
8 eight
0 zero
1 one[/tt]
Solaris 8 nawk
[tt]2 two
3 three
4 four
5 five
6 six
7 seven
8 eight
0 zero
1 one[/tt]
Solaris 8 /usr/xpg4/bin/awk
[tt]8 eight
7 seven
6 six
5 five
4 four
3 three
2 two
1 one
0 zero[/tt]
SCO OpenServer awk
[tt]2 two
3 three
4 four
5 five
6 six
7 seven
8 eight
0 zero
1 one[/tt]
And if I try adding an asort(a) before the for loop in the gawk version, the results are even stranger!
[tt]4 one
5 seven
6 six
7 three
8 two
9 zero
1 eight
2 five
3 four[/tt]
Note the '9' index that has suddenly appeared?
So let's say I wanted to iterate through the array in order... I'd have to use a C-style for (i=0; i<something; i++) loop... but then, how do I know how many elements are in the array? There is no handy function to return that number... although I notice asort() does it, but only as a side-effect.
Freaky.
Annihilannic.
Trying this code in various awks gives surprising results... surprising to me anyway.
Code:
BEGIN {
a[0]="zero"
a[1]="one"
a[2]="two"
a[3]="three"
a[4]="four"
a[5]="five"
a[6]="six"
a[7]="seven"
a[8]="eight"
for (v in a) print v,a[v];
}
Linux gawk 3.1.0
[tt]4 four
5 five
6 six
7 seven
8 eight
0 zero
1 one
2 two
3 three[/tt]
Solaris 8 awk
[tt]2 two
3 three
4 four
5 five
6 six
7 seven
8 eight
0 zero
1 one[/tt]
Solaris 8 nawk
[tt]2 two
3 three
4 four
5 five
6 six
7 seven
8 eight
0 zero
1 one[/tt]
Solaris 8 /usr/xpg4/bin/awk
[tt]8 eight
7 seven
6 six
5 five
4 four
3 three
2 two
1 one
0 zero[/tt]
SCO OpenServer awk
[tt]2 two
3 three
4 four
5 five
6 six
7 seven
8 eight
0 zero
1 one[/tt]
And if I try adding an asort(a) before the for loop in the gawk version, the results are even stranger!
[tt]4 one
5 seven
6 six
7 three
8 two
9 zero
1 eight
2 five
3 four[/tt]
Note the '9' index that has suddenly appeared?
So let's say I wanted to iterate through the array in order... I'd have to use a C-style for (i=0; i<something; i++) loop... but then, how do I know how many elements are in the array? There is no handy function to return that number... although I notice asort() does it, but only as a side-effect.
Freaky.
Annihilannic.