bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] syntax error when setting RS via string concatenation


From: Ed Morton
Subject: Re: [bug-gawk] syntax error when setting RS via string concatenation
Date: Mon, 9 May 2016 09:10:23 -0500
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.0

On 5/9/2016 8:32 AM, Andrew J. Schorr wrote:
On Mon, May 09, 2016 at 08:16:17AM -0500, Ed Morton wrote:
I didn't expect to get this syntax error when setting RS via string 
concatenation:

     $ awk 'BEGIN{RS="[x"; RS=RS"]"}'
     awk: cmd. line:1: fatal: Unmatched [, [^, [:, [., or [=: /[x/

as opposed to setting it to a variable constructed by the same string 
concatenation

     $ awk 'BEGIN{t="[x"; t=t"]"; RS=t}'
     $

Is that a bug or a feature (and if so, what feature?).
I think it's a feature. Consider this:

bash-4.2$ ./gawk 'BEGIN {RS = "[x"}'
gawk: cmd. line:1: fatal: Unmatched [, [^, [:, [., or [=: /[x/

Why should setting RS to an invalid regexp succeed?
Because it's not being used at that point. It's not intuitively obvious that you can't build up the variable in a loop or some such before you use it to separate records which is what I was really doing:

     RS = "["
     for (char in charArray) {
          RS = RS char
          # do other stuff with char
     }
     RS = RS "]"

  There is no way for gawk to
know that it should ignore RS because you plan to fix it later.
Sure there is, just ignore its value until it's used. I assume testing its validity when evaluated rather than when populated would create a performance issue though.
Your workaround using a temporary variable seems to be the
correct solution.
That's fine, I can workaround it now I know it's an issue. Thanks for the quick response.

     Ed.

Regards,
Andy





reply via email to

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