[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gawk: "print" not allowed in PATTERN, only in ACTION?
From: |
Aharon Robbins |
Subject: |
Re: gawk: "print" not allowed in PATTERN, only in ACTION? |
Date: |
Tue, 3 Jul 2001 15:20:22 +0300 |
Greetings. Re this:
> From: address@hidden (Dan Jacobson)
> Subject: gawk: "print" not allowed in PATTERN, only in ACTION?
> Date: 02 Jul 2001 16:34:06 +0800
>
> The gawk manual's "print" node doesn't say why one can't use "print" in the
> PATTERN portion:
> gawk-3.1.0 '1 && print "wow" && 1{print}'<<!
> mom
> !
That's the definition of the language.
> gawk-3.1.0 '(a=m $1 && (print a > "/dev/stderr")&& a ~ "mom")'<<!
> wwww
> !
>
> An error is triggered at "print".
> Let's say I want to print out some debugging info right then and
> there...
Define a function:
function debugout(name, val)
{
printf("%s = %s\n", name, val) > "/dev/stderr"
return 1
}
(a=(m $1) && debugout("a", a) && a ~ "mom")
Note also that you should parenthesize the string concatenation to make
sure it does what you want.
Hope this helps.
Arnold