Front page | perl.perl5.porters |
Postings from July 2011
Re: [PATCH] Support for 0o/0O octal strings
Thread Previous
|
Thread Next
From:
H.Merijn Brand
Date:
July 4, 2011 02:05
Subject:
Re: [PATCH] Support for 0o/0O octal strings
Message ID:
20110704110532.0e8bc347@pc09.procura.nl
On Mon, 04 Jul 2011 10:54:42 +0200, Johan Vromans
<jvromans@squirrel.nl> wrote:
> "H.Merijn Brand" <h.m.brand@xs4all.nl> writes:
>
> > $ perl -wle'print 0x'
> > 0
>
> This should be a syntax error.
> (Unless, of course, there's a formal statement in the Perl docs that
> says that this is valis.)
>
> > my $base16 = tonumbase (16, 8364, "0x"); # 0x20ac
> >
> > just brainstorming there (the optional argument - when passed - adds a
> > (predefined) prefix unless the content is a unknown prefix in which
> > case it prefixes the passed argument.
>
> Trying to understand...
>
> tonumbase (16, 8364); # 20ac or 0x20ac?
20ac
> tonumbase (16, 8364, "0x"); # 0x20ac
> tonumbase (16, 8364, "0X"); # 0X20ac or 0X20AC?
open to discussion. I don't care, I was just brainstorming
> tonumbase (16, 8364, "xy"); # xy20ac???
yes
> If I recall correctly, we already have a built-in that does this. It's
> called sprintf.
>
> sprintf "%x", 8364; # 20ac
> sprintf "0x%x", 8364; # 0x20ac
> sprintf "0x%X", 8364; # 0x20AC
That only "does" the known bases %o for base-8 (octal), %d for base-10
(decimal) and %x for base-16 (hexadecimal). I just used base-16 as an
example.
As Claes already noted, there are already two modules available:
Math::Int2Base and Math::NumberBase.
--
H.Merijn Brand http://tux.nl Perl Monger http://amsterdam.pm.org/
using 5.00307 through 5.14 and porting perl5.15.x on HP-UX 10.20, 11.00,
11.11, 11.23 and 11.31, OpenSuSE 10.1, 11.0 .. 11.4 and AIX 5.2 and 5.3.
http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/
http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/
Thread Previous
|
Thread Next