bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Non-bug suggestions


From: Jack Kelley
Subject: Non-bug suggestions
Date: Tue, 11 Sep 2007 12:43:45 +1000

Arnold, here (as promised) are suggestions for chapter 5. Rather
time-consuming in comparison with the ones I sent for chapters 3 & 4.
--Jack



'GAWK: Effective AWK Programming'
(Edition 3, June 2005)

Suggestions for revising CHAPTER 5

5.10 Page 86 par 2:
#########################################################
'The basic idea is that user input that looks numeric
-- and only user input -- should be treated as numeric,
even though it is actually made of characters and is
therefore also a string. Thus, for example, the string
constant " +3.14" is a string, even though it looks
numeric, and is never treated as number for comparison
purposes.'

####

THE FIRST SENTENCE IS IMPORTANT AND INTERESTING!
The second sentence switches the context unexpectedly
and should perhaps begin with "Meanwhile" rather than
"Thus".

Could this paragraph be expanded and improved?
Here is my suggestion (which could be amplified by
expanding on the third dot point on page 85, and
footnote 3 about the revised standard):

####

The basic idea is that user input that looks numeric
-- and only user input -- should be treated as numeric.
As far as an awk program is concerned, all user input
is variable data. All user input is made of characters,
so is first and foremost of string type; input strings
that look numeric are therefore given the strnum attribute.
Thus, the 6-character input string " +3.14" receives the
strnum attribute. In contrast, the 8-character literal
" +3.14" appearing in program text is a string constant,
and is never treated as a number for comparison purposes.

echo ' +3.14' | gawk '$0==" +3.14"'     # TRUE
echo ' +3.14' | gawk '$0=="+3.14"'      # false
echo ' +3.14' | gawk '$0=="3.14"'       # false
echo ' +3.14' | gawk '$0==3.14'         # TRUE

echo ' +3.14' | gawk '$1==" +3.14"'     # false
echo ' +3.14' | gawk '$1=="+3.14"'      # TRUE
echo ' +3.14' | gawk '$1=="3.14"'       # false
echo ' +3.14' | gawk '$1==3.14'         # TRUE

#########################################################

5.11 Page 89 example

$1=="START"     { interested = ! interested; next }
interested == 1 { print }
$1=="END"       { interested = ! interested; next }

is wrong (prints "END" lines), should be:

$1=="START"     { interested = ! interested; next }
$1=="END"       { interested = ! interested; next }
interested == 1 { print }

But that is also wrong for input where START/END lines
are not given as expected. A safer alternative:

$1=="START"  { q = 1; next }
$1=="END"    { q = 0 }
q { print }

which is still deficient, nor does it illustrate "!".

CONCLUSION: either replace or delete the entire example
(from page 89 line 1 "For example" to the end of 5.11)!

#########################################################

5.13 Page 90 par 4:

"   With built-in functions, space before the parenthesis is
harmless, but it is best not to get into the habit of using
space to avoid mistakes with user-defined functions. Each
function expects a particular number of arguments."
-->
"<<<DELETE PARAGRAPH-BREAK>>> (Space following a built-in
function name is silently ignored.)<<<PARAGRAPH-BREAK>>>
   Each function expects a particular number of arguments."

#########################################################

5.13 Page 90 par 6: "A function can also have side
effects, such as assigning values to certain variables
or doing I/O."

The example which follows does not illustrate side effects.
Suggest replacing with something more appropriate and
interesting: gsub() or split().

#########################################################

5.14 Page 91: % operator: "modulus" --> "remainder"
                 (for consistency with 5.5 Page 79)

#########################################################




Jack Kelley
Senior Computer Support Officer (GIS)
Botanical Sciences
Environmental Sciences Division
ENVIRONMENTAL PROTECTION AGENCY
Queensland, Australia

[Queensland Herbarium, 
Mt Coot-tha Road, TOOWONG, 4066]
Tel: (07) 3896 9670
Fax: (07) 3896 9624
mailto:address@hidden


___________________________
Disclaimer

WARNING: This e-mail (including any attachments) has originated from a 
Queensland Government department and may contain information that is 
confidential, private, or covered by legal professional privilege, and may be 
protected by copyright.  

You may use this e-mail only if you are the person(s) it was intended to be 
sent to and if you use it in an authorised way.  No one is allowed to use, 
review, alter, transmit, disclose, distribute, print or copy this e-mail 
without appropriate authority.  If you have received this e-mail in error, 
please inform the sender immediately by phone or e-mail and delete this e-mail, 
including any copies, from your computer system network and destroy any 
hardcopies.

Unless otherwise stated, this e-mail represents the views of the sender and not 
the views of the Environmental Protection Agency.

Although this e-mail has been checked for the presence of computer viruses, the 
Environmental Protection Agency provides no warranty that all viruses have been 
detected and cleaned. Any use of this e-mail could harm your computer system.  
It is your responsibility to ensure that this e-mail does not contain and is 
not affected by computer viruses, defects or interference by third parties or 
replication problems (including incompatibility with your computer system).

E-mails sent to and from the Environmental Protection Agency will be 
electronically stored, managed and may be audited, in accordance with the law 
and Queensland Government Information Standards (IS31, IS38, IS40, IS41 and 
IS42) to the extent they are consistent with the law.

___________________________





reply via email to

[Prev in Thread] Current Thread [Next in Thread]