Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^16: why are hex values not numbers? (octal)

by BrowserUk (Patriarch)
on Oct 02, 2016 at 10:56 UTC ( #1173116=note: print w/replies, xml ) Need Help??


in reply to Re^15: why are hex values not numbers? (octal)
in thread why are hex values not numbers?

most of the thread didn't even try to give a reason

Hm. "A string containing "OX84AB97" could be a color code; and one containing "007 James Bond" ..." responded to with "Using a rule of 'leading 0' for octal or 'leading 0x' for hex seem fairly safe -- can you give an example where doing so would be a problem?

Ignores the examples given, makes a bland naive statement, and then asks for examples. Pointless to discuss, if what is written isn't read.

  • Comment on Re^16: why are hex values not numbers? (octal)

Replies are listed 'Best First'.
Re^17: why are hex values not numbers? (octal)
by Anonymous Monk on Oct 03, 2016 at 07:38 UTC

    I had this thought before :)

    now perl gives warning

    Argument "0x41" isn't numeric in printf

    Very clean, things we know are numbers and can unambiguously identify as numbers, we treat as numbers, all other stuff we warn about

    But if definition of numeric was expanded to include more ambiguous num formats, then perl would need a new warning

    treating "0x41" as numeric , might be wrong thing to do, silence with +"no warnings q/extranumeric/;"

    I'm confused why perl-diddler hasn't posted use extranumeric; yet :D

      But if definition of numeric was expanded to include more ambiguous num formats, then perl would need a new warning: treating "0x41" as numeric , might be wrong thing to do, silence with "no warnings q/extranumeric/;"

      That's a (the first) plausible approach to the proposition. It is certainly doable; but at what benefit and what cost?

      Ignoring for now the old saw of backward compatibility. (Though it certainly wouldn't be ignored by the only persons whom opinions matter in this regard, namely the denizens of p5p.)

      The "benefit" would be that the programmer expecting non-decimal numbers in string input could write:

      print "%d\n", $string;

      Rather than:

      printf "%d\n", hex( $string );

      And the cost would be implicitly calling hex every time a scalar currently holding a PV, is used in a numeric context.

      That doesn't seem such a bad thing. (At least if it had been that way since the beginning: Ba-w-d co-pa-bil-ty!)

      But, either this is going to warn "might be wrong thing" every time it finds an extranumeric and the programmers who don't want that will have to disable it; or it will be silent and the programmers that do want the warning, will have to explicitly enable it.

      Seems to me that for those few that do, something like this is just as easy:

      sub myHex { no warnings 'digit'; hex( $_[0] }; } printf "%d\n", myHex( $string );

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2022-12-07 19:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?