develooper Front page | perl.perl5.porters | Postings from July 2011

Re: [PATCH] Support for 0o/0O octal strings

Thread Previous | Thread Next
From:
Johan Vromans
Date:
July 4, 2011 01:54
Subject:
Re: [PATCH] Support for 0o/0O octal strings
Message ID:
m239im77e5.fsf@phoenix.squirrel.nl
"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?
tonumbase( 16, 8364, "0x" );	# 0x20ac
tonumbase( 16, 8364, "0X" );	# 0X20ac or 0X20AC?
tonumbase( 16, 8364, "xy" );	# xy20ac???

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

-- Johan

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About