Re: Arrays
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: Arrays

From: <ohhohe@gmail.com>
Date: Fri Dec 23 2005 - 08:18:03 CET

#***************************************************************
# PROCEDURE
# initServiceNames
#
# DESCRIPTION
# Initiate Service Names variables defined by Config.txt
# into user context (upvar and uplevel)
#
# ARGUMENTS
#
#
#***************************************************************
proc ::common::initServiceNames {} {
    global CONFIG_FILENAME
    variable ARR_VAR
    set oldwd [pwd]
    set isConfig 0
    if {$ARR_VAR(DEBUG)} {puts "\nDEBUG: Initialize service names
definition...."}
    if { ![info exists CONFIG_FILENAME] } {
        cd ..
        cd ..
        set filename "Config.txt"
    } else {
        regsub -all {\\} $CONFIG_FILENAME {\\\\} filename
    }
    if { ![catch {set file [open $filename]}] } {
        set data [read $file]
        close $file
        set lines [split $data "\n"]
        foreach line $lines {
            set line [string trimleft $line]
            if { [ regexp {^\[service_names\]} $line ] } {
                set isConfig 1
            } elseif { [regexp {^\[} $line] } {
                set isConfig 0
            } elseif { (![regexp {^#} $line]) && $isConfig} {
                if {[regexp {([^=]*)=(.*)} $line -> key value]} {
                    set key [string trimright $key]
                    set value [string trimleft $value]
                    uplevel set $key \"$value\"
                    if {$ARR_VAR(DEBUG)} {puts [format "%-*s= %s" 20
$key $value]}
                }
            }
        }
    } else {
        cd $oldwd
        return -code error "ERROR: Cannot locate $filename. Abort !!"
    }
    cd $oldwd

krithiga81@yahoo.com wrote:

> Hi
> I am trying to read a config file and place data into global arrays
> for each section I have in the config file. I was trying to use array
> get with pattern but does not work. Any suugestions of how this can be
> implemented
>
> Thanks
> krithiga
Received on Fri Dec 23 19:03:13 2005