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

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

Thread Previous | Thread Next
From:
Claes Jakobsson
Date:
July 3, 2011 15:27
Subject:
Re: [PATCH] Support for 0o/0O octal strings
Message ID:
C4C282F9-51C6-4A73-B90A-9F70D1B9C86F@surfar.nu

On 3 jul 2011, at 23.43, Father Chrysostomos wrote:
> Claes Jakobsson wrote:
>> Hi,
>> 
>> the attached patches
>> 
>> 1) Adds support + tests for 0o and 0O octal string constants
>> 2) Adds 0o and 0O to grok_oct hence making oct() also understand the above + tests
>> 3) removes the task from perltodo
>> 
>> /Claes
> 
> Before the patches:
> 
> $ ./miniperl -e '0or foo()'
> Undefined subroutine &main::foo called at -e line 1.
> 
> After the patches:
> 
> $ ./miniperl -e '0or foo()'
> Bareword found where operator expected at -e line 1, near "0or"
> 	(Missing operator before r?)
> syntax error at -e line 1, near "0or foo"
> Execution of -e aborted due to compilation errors.
> 
> Is there any way to resolve this in favour of backward compatibility? (Honestly, I don’t see what benefit this feature provides, even though it’s listed in perltodo.)

Interesting. The same behavior (but reversed) exists with 'x' 

$ ./miniperl -e '0x foo()'
Bareword found where operator expected at -e line 1, near "0x foo"
	(Missing operator before foo?)
syntax error at -e line 1, near "0x foo"
Execution of -e aborted due to compilation errors.

$ ./miniperl -e '0 x foo()'
Undefined subroutine &main::foo called at -e line 1.

But yes, it should be possible the retain backwards compatibility if we also that the character following 'o' is valid octal.

  } else if ((s[1] == 'o' || s[1] == 'O') && (s[2] >= '0' && s[2] <= '7')) {

now my

$ ./miniperl -e '0or foo()'
Undefined subroutine &main::foo called at -e line 1.

$ ./miniperl -e 'print 0o31'
25

Regarding the benefit of 0o I don't see any good reason either except it was listed in perltodo and it can be abused for poetry =)

Do we want this feature really? I'd rather see an arbitrary base numeric literal like erlang has.

  > 5#41.
  21

  > 28#Perl.
  560553

Perhaps a syntax like 0[<base>]<number> (suggestions welcome!), the above would then be 0[28]Perl. Erlang limits the base to 36 tho as this is where it runs out of 0-9A-Z.

/Claes


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