Perl-Sensitive Sunglasses | |
PerlMonks |
Re: convert script from perl to tclby atcroft (Abbot) |
on Aug 08, 2019 at 03:55 UTC ( [id://11104130]=note: print w/replies, xml ) | Need Help?? |
The problem I saw (from printing the values just after proc entry) was that $output was not being updated. Since I've only had to use TCL a few times (and consider myself still a beginner at it), I just did something that worked-I removed the output variable from the parameter list and used 'upvar #0 output outp' to access it as a global variable. WARNING: If this is some form of homework, the use of a global variable may result in a low or failing grade. TCL Code:
Verification: Output from OP-provided perl script (target: 20; input: [ 2, 3, 5, ]):
Output from above TCL script (target: 20; input: [ 2, 3, 5, ]):
(As an aside, the lack of formatting made both pieces of code hard to follow (although other things may have my focus off tonight as well). I ran the perl code through Perltidy, and the TCL code through the code listed as "reformat2.tcl" here, but I still had to run it with different values to determine what your actual goal was (all combinations of @input that sum to $target).) Hope that helps.
In Section
Seekers of Perl Wisdom
|
|