[nycbug-talk] two quick things

Matthew Story matt at tablethotels.com
Sat Feb 11 23:21:08 EST 2012


In the interest in not propagating misinformation, I wanted to correct a misstatement in the January talk, and I have made the correlating corrections to the slides.

The lack of support for \t (and other \encoded values) was reported to me a few days prior to the talk, I should have looked further into this prior to having made comments in the talk and using:

FS=sprintf("%c", 9);

Instead of:

FS="\t";

While playing around with C's printf recently, I discovered that the lack of support "bug" that was reported to me was really a misunderstanding of where the decoding from \values happens.  The reported bug, I'm pretty sure was the result of something like:

echo "\t" | awk '{ printf("%s", $1); }'

Which will print a literal "\t".  Decoding is actually done when a \encoded value occurs in a constant, and is not a feature of printf.  If awk encounters a literal "\t" in a stream, or otherwise non-constant, it treats it as a literal \t, not an encoded TAB.  This is consistent with C's behavior:

#include <stdio.h>
int
main() {
    static char e[3] = {'\\', 't', '\0'};
    return (-1 == printf(e) || -1 == printf("%s", e)); /* show that printf does not decode literal \t in fmt or replace */
}

This will generate a warning with clang at compile time (cc doesn't seem to mind that ``e'' is not string literal), but is a good demonstration of the fact that \expansion is not a feature of printf.  Anyway, apologies for the misinformation.

On Jan 5, 2012, at 10:48 PM, mikel king wrote:

> 
> On Jan 5, 2012, at 10:40 PM, Matthew Story wrote:
> 
>> the useless use of head, reminds me of my favorite quote from The UNIX Programming Environment ...
>> 
>>     With these ideas, it might seem sensible to write a program, called head, 
>>     to print the first few lines of each filename argument. But sed 3q (or 10q) 
>>     is so easy to type that we've never felt the need.
>>        ~ p.124
> 
> =))
> 
> Love it thanks for sharing...
> 
> m

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nycbug.org/pipermail/talk/attachments/20120211/5643afeb/attachment.html>


More information about the talk mailing list