I have a function that returns a string however I cant store that value into a variable. I tried doing this
% set m [return "This is returned value"]
This is returned value
% puts $m
can't read "m": no such variable
Any suggestions what I might be doing wrong here ? Also I tried something like this
% set m [puts "Test"]
Test
% puts $m
...
the output of m is blank why is that ?
Update :
After looking into this issue. It seems that I have a method that cannot be altered. This method prints an output to the screen. What I want to do is to capture that output in a variable as well.
If you want to return value from a function it should something like this
proc value { } {
return rajesh
}
set result [value]
puts command won't return any value and it will be empty string if you assign it to a variable.
In your first case, you have used return inside the variable assignment like
set m [return "This is returned value"]
Because of return, code will return immediately. It has nowhere to return to. Further code below this of any, won't run at all. That's why the it got failed as
can't read "m": no such variable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With