Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Question on Recursion

by JavaFan (Canon)
on Jan 09, 2009 at 11:52 UTC ( [id://735159]=note: print w/replies, xml ) Need Help??


in reply to Question on Recursion

Now that you have found the recursion problem, I'd write it without recursion. Or looping.
print "$num == 9\n" unless $num % 9;
will do as well.

Replies are listed 'Best First'.
Re^2: Question on Recursion
by roboticus (Chancellor) on Jan 09, 2009 at 13:23 UTC
    JavaFan:

    Not quite ... it'll only print the 9s! I'd suggest:

    print "num=$num, result=", ($num ? substr("912345678", $num%9, 1) : 0) +, "\n";
    ...roboticus
      Well, considering the OP has:
      print "$num == 9\n" if ($total1 == 9);
      only printing the 9s was done on purpose, as that's what the OP is doing.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2024-03-28 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found