Café BilderBuch die Amika Methode   
Lesezeichen [ Jobs # QR-Code # Projekte ]Sa 22 Juni 2024 20:26:31 # Grundlagen der Programmierung | Tcl Tutorial.


. Modularization - source .

[ Previous | Index | Next ]

The source command will load a file and execute it. This allows a program to be broken up into multiple files, with each file defining procedures and variables for a particular area of functionality. For instance, you might have a file called database.tcl that contains all the procedures for dealing with a database, or a file called gui.tcl that handles creating a graphical user interface with Tk. The main script can then simply include each file using the source command. More powerful techniques for program modularization are discussed in the next lesson on packages.

This command can be used to:

  • separate a program into multiple files.
  • make a library file that contains all the procs for a particular set of functions.
  • configure programs.
  • load data files.
source fileName
Reads the script in fileName and executes it. If the script executes successfully, source returns the value of the last statement in the script.
If there is an error in the script, source will return that error.
If there is a return (other than within a proc definition) then source will return immediately, without executing the remainder of the script.
If fileName starts with a tilde (~) then $env(HOME) will substituted for the tilde, as is done in the file command.


. Example .

   # Example data file to be sourced
   set scr [info script]
   proc testproc {} {
    global scr
    puts "testproc source file: $scr"
   set abc 1
   set aaaa 1

   set filename "sourcedata.tcl"
   puts "Global variables visible before sourcing $filename:"
   puts "[lsort [info globals]]\n"

   if {[info procs testproc] == ""} {
    puts "testproc does not exist. sourcing $filename"
    source $filename

   puts "\nNow executing testproc"

   puts "Global variables visible after sourcing $filename:"
   puts "[lsort [info globals]]\n"

[ Home | Top ]
[ . Previous | Index | Next . ]
Der Inhalt dieser Seite wurde am 06.11.2019 um 12.19 Uhr aktualisiert.
Navigation Seminare Magic Software Projekte Publikationen Kontakt Home
   huecker dot com * Germany | Datenschutz
© 1999, 2024 Franz-Josef Hücker. All Rights Reserved.
Contact Print Page LinkedIn follow me on twitter RSS Feeds & Podcasts