Oct. 28th, 2024

miriam_e: from my drawing MoonGirl (Default)
One of the disadvantages of a small language like awk is the lack of some functions. It's also a great advantage as it is not a gigantic, sprawling language the way many have become nowadays.

Today I encountered the disadvantage, in that I needed something that worked like the eval() function many languages have, that would let me read in a string and execute it. In this case I had a long list of variables and the values I wanted stored into them. I needed to be able read them in to my program.

I tried a few ideas, including a few proposed by ChatGPT-4o. None worked... until I came up with a solution that even GPT-4 hadn't heard of. I made the settings file (named ".canvas") into a fake awk file with
function settings(){
at the top, then a list of the variable assignments, and the last line the closing curly brace.

In my main awk file I have
@include "./.canvas"
near the top of the file and whenever I want to read the variables into my program I simply have
settings()
in my program. Easy peasy. Yay! :D

Profile

miriam_e: from my drawing MoonGirl (Default)
miriam_e

May 2025

S M T W T F S
    123
45678910
11121314151617
18192021222324
252627282930 31

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 14th, 2025 05:53 pm
Powered by Dreamwidth Studios