in reply to how can i hold temporary values in a recursive function

Add strictures then turn your sketch into real code. At present there are too many places where it is not clear what you want to happen because of errors in your code (bare words 'begin' and 'end' and multiplications in void context for example). If the general help others have offered isn't enough to solve your problem then we need something that can actually be run.

True laziness is hard work
  • Comment on Re: how can i hold temporary values in a recursive function

Replies are listed 'Best First'.
Re^2: how can i hold temporary values in a recursive function
by educated_foo (Vicar) on Apr 20, 2010 at 02:51 UTC
    It would be polite for you to make at least a minimal effort to understand the OP. For example, when the OP says
    #maximum of below foreach# foreach my $yy ( keys %{$trans->{$state}} ) { $trans->{$state}->{$yy} * viterbi($yy, $r) ; }
    it's obvious he means max(map { ... } keys ...) We're humans here, not computers, so we should act like, and treat each other as, humans.

    Of course, you're not obliged to make that effort. But if you don't want to, why waste everyone's time with an unhelpful comment?

      In fact I spent on the order of half an hour playing with the OP's code, but I couldn't figure out what a useful starting condition might be. Revisiting the OP's node I've only just noticed the print "\n\n", viterbi(end, 3); at the end of the large code block. I guess I was misled by the comment 'this part is main part' following the first code fragment into thinking that was the driving code for what followed rather than the 'key part of the code' as, in hind sight, the OP presumably meant. On reflection it's not surprising that my static analysis of the code wasn't getting anywhere fast!

      Bottom line? 'Don't attribute to malice what you can account for by stupidity!'

      True laziness is hard work
        This is useful feedback to the OP; "Add strictures then turn your sketch into real code" is not. Neither the string "use strict;\n" nor some code changes would have made the starting conditions less opaque.