Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax problem

Status
Not open for further replies.

fhutt

Programmer
Jul 7, 2006
79
AU
Hello
I am trying to call a procedure, whose name is in a variable and having some arguments in a separate variable.
set result [$proc1 $com_line]
where $proc1 contains the name of the procedure, doesn't work. The arguments don't get supplied to the procedure.

A tried numerous variants and the best was:
set result [eval [concat $proc1 $com_line]]
This works but runs through the procedure twice. The first time with the correct arguments, but the second time with some unexpected arguments.

How can I correct this "apparently" simple task?
Thanks
 
Hi

I would say, the problem lies somewhere else. Your first call ( the one without [tt]eval[/tt] ) works for me :
Code:
[b]proc[/b] double [teal]{[/teal]what[teal]}[/teal][teal]\[/teal]
[teal]{[/teal]
  [b]expr[/b] [navy]$what[/navy][teal]*[/teal][purple]2[/purple]
[teal]}[/teal]

[b]set[/b] proc1 double
[b]set[/b] com_line [purple]21[/purple]

[b]set[/b] result [teal][[/teal][navy]$proc1[/navy] [navy]$com_line[/navy][teal]][/teal]

[b]puts[/b] [navy]$result[/navy] [gray]# outputs 42[/gray]
Or I misunderstood something ?


Feherke.
 
Feherke, you are so right.
I spent the last day tracking this down and just found the problem.
The procedure I am calling is a lot more complicated than your example. Buried in my procedure I call another procedure, which has worked fine, but I forgot that it calls the first procedure. And there is the second execution. Thank you very much.
 
Feherke, just another note.
The $com_line arguments to the procedure are multiple and without the 'eval' the contents of $com_line are all passed onto the procedure as a single argument. I need to separate them into individual arguments and the eval seems to do that. The 'concat' I don't need.
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top