[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-gawk] "The GNU AWK User's Guide" Section 11.2.1.2 - example program
From: |
address@hidden |
Subject: |
[bug-gawk] "The GNU AWK User's Guide" Section 11.2.1.2 - example program error, maybe |
Date: |
Tue, 16 Aug 2011 11:31:57 -0600 |
I believe I've found a problem with an example program in "The GNU AWK User's
Guide"
Section 11.2.1.2 Controlling Array Scanning Order
The example appears to have 2 problems:
$ gawk 'BEGIN {
> a[4] = 4
> a[3] = 3
> for (i in a)
> print i, a[i]
> }'
-| 4 4
-| 3 3
$ gawk 'BEGIN {
> PROCINFO["sorted_in"] = "@str_ind_asc"
> a[4] = 4
> a[3] = 3
> for (i in a)
> print i, a[i]
> }'
-| 3 3
-| 4 4
__________________
In line 10, of the example, I believe the author meant to use the special value
="@ind_str_asc"
The other issue is that I have run these routines on two systems and the
results are the same
> 4 4
> 3 3
unlike the example, where the second run sorts the rows in ascending order.
Here is a copy of my execution with a variation in the assigned values for my
clarification:
>{252}: cat proc.bsh
gawk 'BEGIN {
a[4] = 4
a[3] = 3
for (i in a)
print i, a[i]
}'
gawk 'BEGIN {
PROCINFO["sorted_in"] = "@ind_str_asc"
a[4] = 40
a[3] = 30
for (i in a)
print i, a[i]
}'
>{253}: bash proc.bsh
4 4
3 3
4 40
3 30
>{254}:gawk --version
GNU Awk 3.1.5
>{256}: uname -a
Linux 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 x86_64 x86_64
GNU/Linux
I am a newbie with awk and especially gawk, so it's very possible that I missed
the authors intent.
Hope this is helpful.
thx
-The Hobbit (aka Frank)
- [bug-gawk] "The GNU AWK User's Guide" Section 11.2.1.2 - example program error, maybe,
address@hidden <=