in reply to I need Hex conversion, not!

This works, but it will give you a slight performance hit. Unless you're doing serious number crunching it'll probably be acceptable...

use strict; use warnings; sub hexnum { package HexNum; use base 'Math::BigInt'; use overload q[""] => 'as_hex'; __PACKAGE__->new(@_); } my $var = hexnum 0x2F; $var += 3; $var += hexnum 0x02; print "$var\n";
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re^2: I need Hex conversion, not!
by Anonymous Monk on Jan 07, 2013 at 17:17 UTC

    Wow, that is cool. Btw, is there a way to ignore 0x prefix without substr, or anything ?

      use strict; use warnings; sub hexnum { package HexNum; use base 'Math::BigInt'; use overload q[""] => 'as_hex_without_0x'; __PACKAGE__->new(@_); } sub HexNum::as_hex_without_0x { substr($_[0]->as_hex, 2); } my $var = hexnum 0x2F; $var += 3; $var += hexnum 0x02; print "$var\n";
      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'