• Split a large script into smaller scripts

    From Hassan Iqbal@21:1/5 to All on Tue Oct 12 15:44:42 2021
    I have a large TCL script, currently 2,774 lines. This is expected to continue to get longer with time. I have decided to split this into several files. The script consists of a header that branches into one of two if statements that contain a lot of
    code. Following this is a creation of dictionary that has a few hundred lines of code. Following this is a lot of procedures that rely on the dictionary and few other variables created at start of script.

    Thus, start
    (1) Declare "environment variables" that tell script what part to execute in first 1/4 as form of init/setup routine
    (2) Code that performs init/setup function based on values it gets from (1)
    (3) Create a massive dictionary that is basically a mapping between name and integers
    (4) A whole lot of procedures that do different things and can be grouped into what part of system they affect
    (5) A final procedure that does some setup before the script ends

    Once the script is executed in the TCL terminal, I then call the loaded procedures as required. Now my question is, what options exist for me to split this into smaller files and how will these pieces be brought together when the script is loaded?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Uwe Klein@21:1/5 to All on Wed Oct 13 08:58:56 2021
    Am 13.10.21 um 00:44 schrieb Hassan Iqbal:
    I have a large TCL script, currently 2,774 lines. This is expected to continue to get longer with time. I have decided to split this into several files. The script consists of a header that branches into one of two if statements that contain a lot of
    code. Following this is a creation of dictionary that has a few hundred lines of code. Following this is a lot of procedures that rely on the dictionary and few other variables created at start of script.

    Thus, start
    (1) Declare "environment variables" that tell script what part to execute in first 1/4 as form of init/setup routine
    (2) Code that performs init/setup function based on values it gets from (1) (3) Create a massive dictionary that is basically a mapping between name and integers
    (4) A whole lot of procedures that do different things and can be grouped into what part of system they affect
    (5) A final procedure that does some setup before the script ends

    Once the script is executed in the TCL terminal, I then call the loaded procedures as required. Now my question is, what options exist for me to split this into smaller files and how will these pieces be brought together when the script is loaded?

    factorize your code.

    create files each containing connected groups of procs and code snippets. separate configuration information from code

    either incorporate them via

    source $file

    or wrap each utility with a [package provide myutil] statement
    and use package require myutil .. in your main script.


    so you will have to look into these tcl commands

    source ...

    package ...

    also look into [namespace] functionality.

    Uwe

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)