From: Kenny McCormack on
In article <89298dd2-d42f-4e41-a8d3-938faefa3a29(a)c19g2000prf.googlegroups.com>,
twf_cc <twfccc(a)gmail.com> wrote:
....
>I have re-writen my script with your hints, it work fine. Thankyou
>about the book `sed & awk' 2e, the author is Dale dougberty and Arnold
>Robbins, produced by O'REILLY
>My book is chinese version, in chapter 7 , it is given a usage:
>printf( format_expression[,arguments])
>some exsample from the book
>printf("|%10s|\n", "hello")
>printf("|%-10s|\n", "hello")
>
>In chapter 10, there is an example, that is a function, sometime used
>( ), sometimes not used

As far as I'm concerned, Ed's been smoking something foul when it comes
to his position on printf(). I.e., he is wrong.

The parens are fine, and, as is pointed out in many books, there is one
particular case where they are necessary.

Ed's example(s), on the other hand, are totally contrived, and boil down
to "I did something stupid and the program didn't give me exactly the
error message I expected".

We need to keep in mind that C/Awk/etc have always been "Ken
Thompson-like" in terms of their error messages and error reporting.

From: pk on
Ed Morton wrote:

> $ awk -F'(</td>)?[[:space:]]+<td>' -v RS='\n</tr>\n' '

Just out of curiosity, is this portable? According to the standard, if RS
consists of more than a single character, the results should be
unspecified.

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
From: Ed Morton on


On 3/29/2008 9:57 AM, pk wrote:
> Ed Morton wrote:
>
>
>>$ awk -F'(</td>)?[[:space:]]+<td>' -v RS='\n</tr>\n' '
>
>
> Just out of curiosity, is this portable? According to the standard, if RS
> consists of more than a single character, the results should be
> unspecified.
>

No, it's not portable, but the OP is using gawk....

Ed.

From: Ed Morton on


On 3/29/2008 6:03 AM, Kenny McCormack wrote:
> In article <89298dd2-d42f-4e41-a8d3-938faefa3a29(a)c19g2000prf.googlegroups.com>,
> twf_cc <twfccc(a)gmail.com> wrote:
> ...
>
>>I have re-writen my script with your hints, it work fine. Thankyou
>>about the book `sed & awk' 2e, the author is Dale dougberty and Arnold
>>Robbins, produced by O'REILLY
>>My book is chinese version, in chapter 7 , it is given a usage:
>>printf( format_expression[,arguments])
>>some exsample from the book
>>printf("|%10s|\n", "hello")
>>printf("|%-10s|\n", "hello")
>>
>>In chapter 10, there is an example, that is a function, sometime used
>>( ), sometimes not used
>
>
> As far as I'm concerned, Ed's been smoking something foul when it comes
> to his position on printf(). I.e., he is wrong.

My position is that printf isn't a function and so the brackets are redundant at
best and can lead to unexpected results if you think they're part of the
function call. Those are just facts so you can't be disagreeing with that. I
further think that means you shouldn't use them as if they were part of a
function call so I assume that's where you disagree.

> The parens are fine, and, as is pointed out in many books, there is one
> particular case where they are necessary.

As I asked in a different thread, can you please post that case?

> Ed's example(s), on the other hand, are totally contrived, and boil down
> to "I did something stupid and the program didn't give me exactly the
> error message I expected".

Not quite - it boils down to "I did something stupid that I thought should be a
syntax error and the program didn't give me any error message at all". I agree
the example I posted is contrived but in my experience when there's one "gotcha"
about misunderstanding a language construct/paradigm/idiom, there's usually
others which is why I think it's worth pointing out this case.

I just don't see any benefits to habitually putting the printf arguments inside
parentheses but maybe the example you're going to post will convince me otherwise.

Just curious - do you think people should use parens around the "print"
arguments too?

Ed.