Thread View: gnu.utils.bug
2 messages
2 total messages
Started by Don Stewart
Mon, 06 Apr 1992 05:55
gawk anomaly?
Author: Don Stewart
Date: Mon, 06 Apr 1992 05:55
Date: Mon, 06 Apr 1992 05:55
26 lines
1508 bytes
1508 bytes
In the following, the line 'print "class:"$0' prints nothing as the code now stands.
HOwever, by uncommenting 'print class[$2]', the above DOES print.
What am i doing wrong? (fails even in this stripped eg)
---------------------------------
/depot/gnu/bin/gawk '
FILENAME == "rt.crse" { # fmt of crse data: crse#[.A-H]section{\t}instructor
course[$1]=$2 # eg. 103.001 smith
} # 497B001 wesson
FILENAME == "SHIELDS.data" { # student registration data
if(substr($0,52,1) != " ") # data has space if no course letter
crse = substr($0,49,7) # eg. convert '103 001' -> '103.001'
else
crse = substr($0,49,3)"."substr($0,53,3)
if (crse in course) {
class[substr($0,22,9)] = class[substr($0,22,9)] ":" crse
#'22,9' is ssn
}
}
FILENAME == "masterssn" {
OFS = ":"
# print class[$2] #bad side effect: this creates entry for $2 w/ null value
if ($2 in class) {
print "class:"$0
}
}
' FS=" " rt.crse FS=":" masterssn SHIELDS.data
Re: gawk anomaly?
Author: Noah Friedman
Date: Tue, 07 Apr 1992 05:51
Date: Tue, 07 Apr 1992 05:51
17 lines
1221 bytes
1221 bytes
>In the following, the line 'print "class:"$0' prints nothing as the code now stands.
>HOwever, by uncommenting 'print class[$2]', the above DOES print.
>What am i doing wrong? (fails even in this stripped eg)
By referencing class[$2], you are automatically creating an index in
class even if it didn't exist previously. Thus, when you uncomment this
line you are causing the condition "if ($2 in class)" to become true.
The reason why the print "class:"$0 doesn't get printed is that that
particular block doesn't get executed at all as the code now stands.
>...
># print class[$2] #bad side effect: this creates entry for $2 w/ null value
> if ($2 in class) {
> print "class:"$0
> }
>...
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads