Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Program Not Printing Help

by BillKSmith (Chaplain)
on May 16, 2014 at 19:52 UTC ( #1086385=note: print w/ replies, xml ) Need Help??


in reply to Re: Program Not Printing Help
in thread Program Not Printing Help

Dave, Please explain the reason for the zero. It appears to force the scalar result to be a number rather than a string.

Bill


Comment on Re^2: Program Not Printing Help
Re^3: Program Not Printing Help
by davido (Archbishop) on May 17, 2014 at 04:07 UTC

    That's a good question. Reverse treats its scalar operand as a string, which works fine most of the time, with one notable exception.

    My understanding of numerical palindromes is that 01 should be treated as a number such that its palindrome is 1. If I don't force the value to be cast as a number, reverse will return 10 if given 01 to start with. This may be appropriate for strings, but for numeric values the leading zero should be disregarded, as it is not significant.

    It's possible I'm wrong in my interpretation of how numbers with leading zeros should be treated when considering whether they are palindromes, but my interpretation makes sense to me in my possible ignorance. ;)

    By casting our input as a number before handing it to reverse, we cause the leading zeros to vanish before reverse has a chance to see them and do the wrong thing with them.


    Dave

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2014-12-23 01:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (133 votes), past polls