Front page | perl.perl5.porters |
Postings from April 2003
Re: [perl #21875] Hash ref transformed as a list
Thread Previous
|
Thread Next
From:
Nicholas Clark
Date:
April 7, 2003 15:00
Subject:
Re: [perl #21875] Hash ref transformed as a list
Message ID:
20030407215646.GD275@Bagpuss.unfortu.net
On Mon, Apr 07, 2003 at 05:43:09PM -0000, pierre denis wrote:
> ## Demonstrate a bug in perl 5.8 when the first key of a hash ref
> ## starts with the letter 'q' unquoted
> ##
> ## Pierre Denis (pdenis@fotango.com)
> ## Fotango
>
> use Data::Dumper;
>
> print "isList() => Should return a hash ref, but returns a list ".Dumper(isList());
> print "stillList() => Should return a hash ref, but returns a list ".Dumper(stillList());
> print "isHashRef() => Does return a hash ref ".Dumper(isHashRef());
>
> sub isList {
> {
> q => undef,
> foo => 'bar',
> };
> }
>
> sub isHashRef {
> {
> 'q' => undef,
> foo => 'bar',
> };
> }
>
> sub stillList {
> {
> quality => 'bad',
> foo => 'bar',
> };
> }
It appears to be a parser bug. If I add unary plus I defeat the guesswork in
the parser. However, it is only for strings starting q because if I run this:
use strict;
use warnings;
use Data::Dumper;
foreach my $letter ('a'..'z') {
print Dumper eval <<"EOC";
{
$letter => undef,
foo => 'bar',
};
EOC
print Dumper eval <<"EOC";
{
${letter}ed => undef,
foo => 'bar',
};
EOC
print Dumper eval <<"EOC";
+{
$letter => undef,
foo => 'bar',
};
EOC
print Dumper eval <<"EOC";
+{
${letter}ed => undef,
foo => 'bar',
};
EOC
}
$VAR1 = {
'a' => undef,
'foo' => 'bar'
};
$VAR1 = {
'foo' => 'bar',
'aed' => undef
};
$VAR1 = {
'a' => undef,
'foo' => 'bar'
};
$VAR1 = {
'foo' => 'bar',
'aed' => undef
};
all the way, except for this:
$VAR1 = 'q';
$VAR2 = undef;
$VAR3 = 'foo';
$VAR4 = 'bar';
$VAR1 = 'qed';
$VAR2 = undef;
$VAR3 = 'foo';
$VAR4 = 'bar';
$VAR1 = {
'q' => undef,
'foo' => 'bar'
};
$VAR1 = {
'foo' => 'bar',
'qed' => undef
};
$ perl5.8.0 -le "use strict; print q uI think that it's related to this u"
I think that it's related to this
I suspect it's something to do with the q quoting operator, and how you can
safely use any non-whitespace character as quoting. (Although you need the
whitespace after the q if the next character is tokenisable as part of an
identifier)
I've not looked at the tokeniser source. I'm scared of it :-)
Nicholas Clark
Thread Previous
|
Thread Next