Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: A quandry in Towers of Hanoi

by tilly (Archbishop)
on May 15, 2009 at 00:15 UTC ( #764173=note: print w/ replies, xml ) Need Help??


in reply to A quandry in Towers of Hanoi

Your bug is that you are initializing your arrays with:

my @polea = ""; my @poleb = ""; my @polec = "";
which means that they have invisible 0-width entries on top of each stack. Get rid of those and your bug goes away.

Incidentally if you change the way you print slightly, you can turn warnings back on:

for (my $len = 0 ;$len <= $numdisks; $len++) { print join "\t\t\t", map {$_->[$len] || ""} \@polea, \@poleb, \@po +lec; print "\n"; }
(You have to change this in two locations.)


Comment on Re: A quandry in Towers of Hanoi
Select or Download Code
Re^2: A quandry in Towers of Hanoi
by pmonk4ever (Friar) on May 15, 2009 at 16:42 UTC
    Hi, tilly, thank you for your suggestion on the print statement, however, as you can see in my update, something's wrong. I looked up the 'map' function, but perldoc was not very helpful.

    ki6jux

    "No trees were harmed in the creation of this node. However, a rather large number of electrons were somewhat inconvenienced."

      I said \@polea to create a reference to your array while you said \$polea which creates a reference to a non-existent scalar. Hence the problem.

      Implement the print statement as I actually wrote it and the program will run correctly. Also see references quick reference if references are confusing you.

        Oops, I hate it when I do that!

        Thanks, it worked fine.

        ki6jux

        "No trees were harmed in the creation of this node. However, a rather large number of electrons were somewhat inconvenienced."

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2014-08-31 04:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls