Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: A philosophical pondering concerning hexes

by diotalevi (Canon)
on Jun 23, 2004 at 04:10 UTC ( [id://368940]=note: print w/replies, xml ) Need Help??


in reply to A philosophical pondering concerning hexes

I like the idea you are presenting but I balk at your interpretation that oct() and hex() convert or return decimal. They consume a properly formed string and return a number. Perl happens to stringify numbers as their decimal representation. It is only incidental that print hex "0x20" appears to be a hex_string->decimal converter. It is just a hex_string->number converter.

I am not quite sure what the name for numify_hex_string() should be. unhex() is awkward and is still not descriptive of its function.

I also note that oct() doesn't happily consume non-octal data. It just screws up when you do that.

Replies are listed 'Best First'.
Re^2: A philosophical pondering concerning hexes
by tinita (Parson) on Jun 24, 2004 at 11:08 UTC
    I also note that oct() doesn't happily consume non-octal data. It just screws up when you do that.
    huh? oct("0xf") will happily return 15. "0xf" is non-octal in my view...
      My guess is that he means something like:
      $ perl -wle 'print oct 108' Illegal octal digit '8' ignored at -e line 1. 8
      To me, this is just what's Perl is about; regardless of what you throw at it, it does it utter best to make something out of it, and it issues a warning there's something odd about the input. Although in this case, it isn't just Perl that does so - the C functions strtol, and atoi and friends also consume initial portions of a string, stopping at the first character that isn't valid.

      Abigail

        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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-25 10:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found