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

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?

Replies are listed 'Best First'.
Re^3: how can i hold temporary values in a recursive function
by GrandFather (Saint) on Apr 20, 2010 at 05:53 UTC

    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.