Dr.Ruud wrote:
> "Chas Owens" schreef:
>> Dr.Ruud:
> 
>>> Some evaluation is done first:
>>>
>>> perl -Mstrict -MData::Dumper -wle'
>>>   $_ = {0b1_0 => "A", 01_0 => "B", 0x1_0 => "C", 1_0 => "D", _1_0 =>
>>> "E", *_ => "F", \_ => "G"};
>>>   print Dumper $_
>>> '
>>> $VAR1 = {
>>>           '8' => 'B',
>>>           '_1_0' => 'E',
>>>           '*main::_' => 'F',
>>>           '10' => 'D',
>>>           '16' => 'C',
>>>           'SCALAR(0x8062850)' => 'G',
>>>           '2' => 'A'
>>>         };
>> snip
>>
>> Nope, it has nothing to do with evaluation.
> 
> Ah, you misunderstood my "evaluation" which had nothing to do with
> eval(). Maye I should have used "parsing and compiling".
> 
> 
>> The trick is that it only
>> works on barewords (matches /[_A-Za-z][_A-Za-z0-9]*/). 0b1_0 is not a
>> bareword because it starts with a number.  The same goes for 01_0,
>> 0x1_0, and 1_0. _1_0 works because barewords may start with an
>> underscore. *_ and \_ are definitely not a barewords since they
>> contain characters that are not even in the allowed set.  Anything
>> that fails the bareword test is treated as if the '=>' operator were a
>> normal ',' operator.
> 
> Yes, "passing the bareword test" is a better phrase than only mentioning
> "word" characters.
> 
> There are border cases though:
> 
> perl -Mstrict -MData::Dumper -wle'
>   $_ = { AB => 1, +AB => 2, -AB => 3 };
>   print Dumper $_
> '
> $VAR1 = {
>           '-AB' => 3,
>           'AB' => 2
>         };

It depends on what you mean by "border case"?

$ perl -Mstrict -MData::Dumper -wle'
  $_ = { 67 => 1, +67 => 2, -67 => 3 };
  print Dumper $_
'
$VAR1 = {
          '67' => 2,
          '-67' => 3
        };


Unary plus and unary minus appear to be behaving correctly.  :-)




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to