in reply to convert hex string to hex number

Disclaimer: I know nothing about any perl Gtk modules!

There isn't such a thing as a "hex number" in Perl. There are strings that are used to represent hex numbers and they can be converted to integers using oct or hex.

Is the following code any help?

my $hex = "0x3cb37180"; my $dec = oct $hex; say $dec; # 1018392960 say sprintf "0x%X", $dec; # 0x3CB37180

Since you didn't say which module you're using I couldn't check it's documentation to check what $rect->set is expecting


Unless I state otherwise, all my code runs with strict and warnings

Replies are listed 'Best First'.
Re^2: convert hex string to hex number
by grantm (Parson) on Jul 02, 2008 at 23:19 UTC
    There isn't such a thing as a "hex number" in Perl.

    Then how do you explain this ...

    perl -le "print 0x10 + 1" 17

      With perldata. Search for "Scalar value constructors". Your 0x10 is a numeric literal.

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re^2: convert hex string to hex number
by Anonymous Monk on Jan 04, 2012 at 14:07 UTC
    hex(0xAC530000) result Integer Overflow