Article View: gnu.utils.bug
Article #104Re: gawk anomaly?
From: 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
> }
>...
Technical Details
Message-ID:
<9204070551.AA07716@nutrimat.gnu.ai.mit.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!gnu.ai.mit.edu!friedmanReferences:
<92Apr6.095510edt.37072@colossus.cs.psu.edu>Show Full Headers
Complete Article Headers
Newsgroups: gnu.utils.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!gnu.ai.mit.edu!friedman From: friedman@gnu.ai.mit.edu (Noah Friedman) Subject: Re: gawk anomaly? Message-ID: <9204070551.AA07716@nutrimat.gnu.ai.mit.edu> Sender: gnulists@ai.mit.edu Reply-To: friedman@gnu.ai.mit.edu Organization: GNUs Not Usenet References: <92Apr6.095510edt.37072@colossus.cs.psu.edu> Distribution: gnu Date: Tue, 7 Apr 1992 05:51:19 GMT Approved: bug-gnu-utils@prep.ai.mit.edu Lines: 19