Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^2: Program Not Printing Help

by BillKSmith (Vicar)
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.

Replies are listed 'Best First'.
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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1086385]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2018-05-28 06:28 GMT
Find Nodes?
    Voting Booth?