Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: A philosophical pondering concerning hexes

by diotalevi (Canon)
on Jun 24, 2004 at 12:53 UTC ( [id://369330]=note: print w/replies, xml ) Need Help??


in reply to Re: A philosophical pondering concerning hexes
in thread A philosophical pondering concerning hexes

No, I didn't give oct a valid hex number, I gave it an invalid octal number which could have been understood as an otherwise valid decimal number. I had not previously considered that oct() would consume a hex number but since it is implemented using a function shared with hex, I suppose that makes sense.

perl -wle 'print oct "108"' Illegal octal digit '8' ignored at -e line 1. 8

Replies are listed 'Best First'.
Re: A philosophical pondering concerning hexes
by Abigail-II (Bishop) on Jun 24, 2004 at 13:06 UTC
    So, you want something like this?

    inputoct resultComment
    10771Octal
    108108Decimal
    109109Decimal
    10a266Hexadecimal
    10f271Hexadecimal
    10g8Octal, ignoring 'g'

    Does that seem anyway sensible or useful to you? Or perhaps oct 108 should return 89 (because it's base 9?). And should oct 45 be 29 (because it's base 6)?.

    Abigail

      No, the result of oct("108") is "8" but I think it should be undef.

        How do your statements: No, I didn't give oct a valid hex number, I gave it an invalid octal number which could have been understood as an otherwise valid decimal number. and No, the result of oct("108") is "8" but I think it should be undef. relate to each other? 108 is an otherwise valid decimal number. You also seem to be defending, or at least sharing, the OP's ideas. And the OP wants to have a function that given decimal input, returns the decimal representation - so oct 108 (or whatever name this function has) should return 108.

        If you think that oct 108 should be undefined, and not 8, do you also think that $x = "10 dogs" + "5 chickens" should result in $x being undefined, and not 15? What about

        print "Please enter a number: "; my $num = <>; printf "Its square is %d.\n" => $num * $num if $num =~ /^\d+$/;
        Should that print "Its square is 0.", after issueing a warning?

        Abigail

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-19 22:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found