LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-21-2015, 02:19 AM   #1
Jykke
Member
 
Registered: Sep 2005
Posts: 201

Rep: Reputation: 19
tcl procedures and changing variable values inside a procedure


I am trying to avoid use of global variables but I feel like having two left hands with Tcl.

I now tried a simple procedure, hacked it from some examples - it does not work...

Code:
proc incr_a_b_upvar { a b c} {
 puts "a = $a"
 puts "b = $b"
 puts "c = $c"
 upvar 1 $a a_sub
 upvar 1 $b b_sub
 set a_sub $a
 set b_sub $b
 
 puts "a_sub = $a_sub"
 puts "b_sub = $b_sub"
 
 set a [expr {$a + $c}]
 set b [expr {$b + $c}]
}
set a 2
set b 3
set c 1
incr_a_b_upvar $a $b $c
puts "a = $a"
puts "b = $b"
puts "c = $c"
In similar examples it should actually work without those
two set commands inside the procedure
Code:
 set a_sub $a
 set b_sub $b
but without them I get:
Quote:
a = 2
b = 3
c = 1
can't read "a_sub": no such variable
while executing
"puts "a_sub = $a_sub""
(procedure "incr_a_b_upvar" line 10)
invoked from within
"incr_a_b_upvar $a $b $c"
(file "incr_a_b.tcl" line 30)
So what gives?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
TCL quotation Marks inside set construct sumncguy Programming 6 01-09-2015 09:34 AM
[SOLVED] changing variable values with unary vs arithmetic operators atlantis43 Linux - Newbie 9 05-15-2013 10:05 PM
[bash] re-evaluate variable inside variable muzzol Programming 9 12-01-2010 12:31 PM
Cannot type in values in Tcl/Tk graphics window anoopkmr Linux - Software 3 06-06-2008 03:56 PM
tcl/tk $env(HOME) not found inside proc sharky Programming 1 06-01-2008 03:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration