tech-userlevel archive

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

Re: bin/39002: harmful AWK extension: non-portable escaped character




On 13-Jul-08, at 4:31 PM, David Holland wrote:

As far as I can tell what you're claiming is that someone might
intentionally write "foo\.c" in a string constant, intending to get
the value "foo.c", instead of writing it in the normal way without the
backslash.

Exactly, though your example is perhaps pedantic and silly to the extreme.

The point is that the language (as defined for this implementation) clearly shows that the string constants "f\o\o\.\c" and "foo.c" will always compare as identical, eg. with . Furthermore this makes a great deal of sense and is rational behaviour given the context and heritage of the language.

$ awk 'BEGIN {s="foo.c"; t = "f\o\o\.\c"; if (s == t) print "EQUAL!"; printf "'%s'\n", t}'
EQUAL!
foo.c


See P. 40-41 in the AWK book for more about the caveats of using strings as REs.

--
                                        Greg A. Woods; Planix, Inc.
                                        <woods%planix.ca@localhost>



Home | Main Index | Thread Index | Old Index