f



Sourcing a TCL file from within a tcl file

I am a newbie which I am sure I don't need to state :)

I am trying to create a variable with a TCL file that will source
another tcl file when I type the variable name

something like this

if I enter A through my keyboard  then source a.tcl

Can someone show me how to do this

thanks
guy


0
12/10/2008 8:15:14 PM
comp.lang.tcl 23428 articles. 2 followers. Post Follow

14 Replies
1747 Views

Similar Articles

[PageSpeed] 37

On Dec 10, 1:15=A0pm, guy <gcoletta2...@gmail.com> wrote:
> I am a newbie which I am sure I don't need to state :)
>
> I am trying to create a variable with a TCL file that will source
> another tcl file when I type the variable name
>
> something like this
>
> if I enter A through my keyboard =A0then source a.tcl
>
> Can someone show me how to do this
>
> thanks
> guy

What you are asking is not hard.  Will your program have a graphical
user interface?

Aric
0
aric.bills (466)
12/10/2008 8:26:16 PM
On Dec 10, 3:26=A0pm, Aric Bills <aric.bi...@gmail.com> wrote:
> On Dec 10, 1:15=A0pm, guy <gcoletta2...@gmail.com> wrote:
>
> > I am a newbie which I am sure I don't need to state :)
>
> > I am trying to create a variable with a TCL file that will source
> > another tcl file when I type the variable name
>
> > something like this
>
> > if I enter A through my keyboard =A0then source a.tcl
>
> > Can someone show me how to do this
>
> > thanks
> > guy
>
> What you are asking is not hard. =A0Will your program have a graphical
> user interface?
>
> Aric

no I am just using this script to run a sinulation i'm doing.
0
12/10/2008 8:28:31 PM
On Dec 10, 1:28=A0pm, guy <gcoletta2...@gmail.com> wrote:
> On Dec 10, 3:26=A0pm, Aric Bills <aric.bi...@gmail.com> wrote:
>
>
>
> > On Dec 10, 1:15=A0pm, guy <gcoletta2...@gmail.com> wrote:
>
> > > I am a newbie which I am sure I don't need to state :)
>
> > > I am trying to create a variable with a TCL file that will source
> > > another tcl file when I type the variable name
>
> > > something like this
>
> > > if I enter A through my keyboard =A0then source a.tcl
>
> > > Can someone show me how to do this
>
> > > thanks
> > > guy
>
> > What you are asking is not hard. =A0Will your program have a graphical
> > user interface?
>
> > Aric
>
> no I am just using this script to run a sinulation i'm doing.

Okay, you might do something like this (Tcl 8.5):

  set menudata {
    A {-label {Run script A} -script a.tcl}
    B {-label {Run script B} -script b.tcl}
    C {-label {Run script C} -script c.tcl}
    Q {-label {Quit}                      }
  }
  set choice ""
  while {$choice ni [dict keys $menudata]} {
    puts "----\nMenu"
    foreach key [lsort -dictionary [dict keys $menudata]] {
      puts "$key - [dict get $menudata $key -label]"
    }
    puts "\nMake a choice from the options above:"
    gets stdin choice
  }
  if {[dict exists $menudata $choice -script]} {
    source [dict get $menudata $choice -script]
  }
0
aric.bills (466)
12/10/2008 9:13:00 PM
In article <b153e584-4de6-4366-bdef-9df8724bd3c4@w1g2000prk.googlegroups.com>,
guy  <gcoletta2006@gmail.com> wrote:
>On Dec 10, 3:26�pm, Aric Bills <aric.bi...@gmail.com> wrote:
>> On Dec 10, 1:15�pm, guy <gcoletta2...@gmail.com> wrote:
>>
>> > I am a newbie which I am sure I don't need to state :)
>>
>> > I am trying to create a variable with a TCL file that will source
>> > another tcl file when I type the variable name
>>
>> > something like this
>>
>> > if I enter A through my keyboard �then source a.tcl
			.
			.
			.
Is
    source [string tolower $keyboard_entry].tcl
meaningful to you?  To me, that sounds like what you're after.
0
claird (2363)
12/10/2008 10:11:25 PM
On Dec 10, 4:13=A0pm, Aric Bills <aric.bi...@gmail.com> wrote:
> On Dec 10, 1:28=A0pm, guy <gcoletta2...@gmail.com> wrote:
>
>
>
> > On Dec 10, 3:26=A0pm, Aric Bills <aric.bi...@gmail.com> wrote:
>
> > > On Dec 10, 1:15=A0pm, guy <gcoletta2...@gmail.com> wrote:
>
> > > > I am a newbie which I am sure I don't need to state :)
>
> > > > I am trying to create a variable with a TCL file that will source
> > > > another tcl file when I type the variable name
>
> > > > something like this
>
> > > > if I enter A through my keyboard =A0then source a.tcl
>
> > > > Can someone show me how to do this
>
> > > > thanks
> > > > guy
>
> > > What you are asking is not hard. =A0Will your program have a graphica=
l
> > > user interface?
>
> > > Aric
>
> > no I am just using this script to run a sinulation i'm doing.
>
> Okay, you might do something like this (Tcl 8.5):
>
> =A0 set menudata {
> =A0 =A0 A {-label {Run script A} -script a.tcl}
> =A0 =A0 B {-label {Run script B} -script b.tcl}
> =A0 =A0 C {-label {Run script C} -script c.tcl}
> =A0 =A0 Q {-label {Quit} =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> =A0 }
> =A0 set choice ""
> =A0 while {$choice ni [dict keys $menudata]} {
> =A0 =A0 puts "----\nMenu"
> =A0 =A0 foreach key [lsort -dictionary [dict keys $menudata]] {
> =A0 =A0 =A0 puts "$key - [dict get $menudata $key -label]"
> =A0 =A0 }
> =A0 =A0 puts "\nMake a choice from the options above:"
> =A0 =A0 gets stdin choice
> =A0 }
> =A0 if {[dict exists $menudata $choice -script]} {
> =A0 =A0 source [dict get $menudata $choice -script]
> =A0 }

Thanks
Do I just put this is a tcl file an then source that file to get this
to work?
0
12/10/2008 11:17:26 PM
On Dec 10, 5:11=A0pm, cla...@lairds.us (Cameron Laird) wrote:
> In article <b153e584-4de6-4366-bdef-9df8724bd...@w1g2000prk.googlegroups.=
com>,guy =A0<gcoletta2...@gmail.com> wrote:
> >On Dec 10, 3:26=A0pm, Aric Bills <aric.bi...@gmail.com> wrote:
> >> On Dec 10, 1:15=A0pm, guy <gcoletta2...@gmail.com> wrote:
>
> >> > I am a newbie which I am sure I don't need to state :)
>
> >> > I am trying to create a variable with a TCL file that will source
> >> > another tcl file when I type the variable name
>
> >> > something like this
>
> >> > if I enter A through my keyboard =A0then source a.tcl
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .
> Is
> =A0 =A0 source [string tolower $keyboard_entry].tcl
> meaningful to you? =A0To me, that sounds like what you're after.

thanks
can you explain what this does sorry :(
0
12/10/2008 11:28:12 PM
guy wrote:
> I am a newbie which I am sure I don't need to state :)
> 
> I am trying to create a variable with a TCL file that will source
> another tcl file when I type the variable name
> 
> something like this
> 
> if I enter A through my keyboard  then source a.tcl
> 
> Can someone show me how to do this

proc A {} { source a.tcl }

-- Neil
0
nem3909 (1000)
12/10/2008 11:35:51 PM
On Dec 10, 6:35=A0pm, Neil Madden <n...@cs.nott.ac.uk> wrote:
> guy wrote:
> > I am a newbie which I am sure I don't need to state :)
>
> > I am trying to create a variable with a TCL file that will source
> > another tcl file when I type the variable name
>
> > something like this
>
> > if I enter A through my keyboard =A0then source a.tcl
>
> > Can someone show me how to do this
>
> proc A {} { source a.tcl }
>
> -- Neil

Thanks Neil !
0
12/10/2008 11:46:16 PM
Neil Madden wrote:
> proc A {} { source a.tcl }

Beware that

proc A {} {uplevel #0 source a.tcl}

is more likely what you want.

DGP
0
dgporter (104)
12/11/2008 4:14:29 AM
On Dec 10, 11:14=A0pm, Don Porter <dgpor...@verizon.net> wrote:
> Neil Madden wrote:
> > proc A {} { source a.tcl }
>
> Beware that
>
> proc A {} {uplevel #0 source a.tcl}
>
> is more likely what you want.
>
> DGP

why? what does uplevel #0 do?
0
12/11/2008 10:16:19 AM
guy coletta wrote:
> why? what does uplevel #0 do?

It does "run this at the global level". It's probably what you want to
do with the [source] command. :-)

Donal.
0
12/11/2008 10:35:29 AM
On Dec 11, 5:35=A0am, "Donal K. Fellows" <donal.k.fell...@man.ac.uk>
wrote:
> guy coletta wrote:
> > why? what does uplevel #0 do?
>
> It does "run this at the global level". It's probably what you want to
> do with the [source] command. :-)
>
> Donal.

Thanks Donal
0
12/11/2008 11:41:58 AM
In article <7a40e32b-5e66-4656-b6a1-93426b2412dc@v18g2000vbb.googlegroups.com>,
guy  <gcoletta2006@gmail.com> wrote:
			.
			.
			.
>> Is
>> � � source [string tolower $keyboard_entry].tcl
>> meaningful to you? �To me, that sounds like what you're after.
>
>thanks
>can you explain what this does sorry :(

I think you're better off going in the direction Neil and Donal
have sketched; they appear to understand your intent better than
I.

I suspect the best first step in me explaining more would be to
urge you to work through The Tutorial <URL:
http://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.html >.
0
claird (2363)
12/11/2008 4:39:04 PM
On Dec 11, 11:39=A0am, cla...@lairds.us (Cameron Laird) wrote:
> In article <7a40e32b-5e66-4656-b6a1-93426b241...@v18g2000vbb.googlegroups=
..com>,guy =A0<gcoletta2...@gmail.com> wrote:
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .
>
> >> Is
> >> =A0 =A0 source [string tolower $keyboard_entry].tcl
> >> meaningful to you? =A0To me, that sounds like what you're after.
>
> >thanks
> >can you explain what this does sorry :(
>
> I think you're better off going in the direction Neil and Donal
> have sketched; they appear to understand your intent better than
> I.
>
> I suspect the best first step in me explaining more would be to
> urge you to work through The Tutorial <URL:http://www.tcl.tk/man/tcl8.5/t=
utorial/tcltutorial.html>.

Thanks Cameron,
And thanks for the link I have started going through another tutorial,
but I needed to understand this for an application I'm doing now you
know the pressures of having to work for a living :)
0
12/11/2008 6:27:45 PM
Reply: