Perl: the Markov chain saw PerlMonks

### Re: Recursion Confusion

 on Apr 27, 2013 at 11:04 UTC ( #1030952=note: print w/replies, xml ) Need Help??

in reply to Recursion Confusion

A tip from Visualizing recursion with the fib() example is to use Devel::TraceCalls
```#!/usr/bin/perl --
use strict; use warnings;
use Devel::TraceCalls { Subs => [qw/ hanoi /]};
hanoi( 3, 'A', 'C', 'B', 0 );
sub hanoi
{
my (\$n, \$start, \$end, \$extra) = @_;
if (\$n == 1)
{
print "Move disk #1 from \$start to \$end.\n";
}
else
{
hanoi(\$n-1, \$start, \$extra, \$end);
print "Move disk #\$n from \$start to \$end.\n";
hanoi(\$n-1, \$extra, \$end, \$start);
}
}
__END__
[download]```
```TRACE: main::hanoi( 3, 'A', 'C', 'B', 0 )
TRACE: +-main::hanoi( 2, 'A', 'B', 'C' )
TRACE: | +-main::hanoi( 1, 'A', 'C', 'B' )
Move disk #1 from A to C.
Move disk #2 from A to B.
TRACE: | +-main::hanoi( 1, 'C', 'B', 'A' )
Move disk #1 from C to B.
Move disk #3 from A to C.
TRACE: +-main::hanoi( 2, 'B', 'C', 'A' )
TRACE: | +-main::hanoi( 1, 'B', 'A', 'C' )
Move disk #1 from B to A.
Move disk #2 from B to C.
TRACE: | +-main::hanoi( 1, 'A', 'C', 'B' )
Move disk #1 from A to C.
[download]```

Log In?
 Username: Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1030952]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2018-11-18 17:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My code is most likely broken because:

Results (205 votes). Check out past polls.

Notices?