help-gawk
[Top][All Lists]
Advanced

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

Accessing the source code line from within a script


From: chris n
Subject: Accessing the source code line from within a script
Date: Tue, 1 Nov 2022 15:32:03 +0000

Hi,

I have a long script of around 3000 lines at present, and I want to add a trace 
mechanism for logging and debugging purposes. For this, it would be great if 
there was a way to access the source code line from with the script itself. 
Once the code is stable this is not so much of an issue, but at present the 
script is changing and evolving constantly, so I constantly have to update 
source lines manually. So much like NR gives the file input line, a variable 
called say SCL, so that I could write something like:

trace(SCL, "attempting to open output file")
instead of
trace(2148, "attempting to open output file")

function trace(line, message) {
      print systime() " - line : " line " - " message
}

As the debugger knows the source lines, it seems that this value must be 
already known, but not publicly visible from inside a script.

Or maybe there's some other way of doing this ?

Any help would be appreciated,
Chris


reply via email to

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