Are explicitly typed regexes allowed as keys in a Perl YAML dump?
This relates to the previous question: How can I read Perl data structures from Python? ... It might be a bug in the version of the YAML parser I'm working with (0.66), but when I run:
perl -MYAML -le 'do shift; print YAML::Dump( $CPAN::Config )' simple.pl
In the following simple.pl
:
%config = (
'color' => 'red',
'numbers' => [5, 8],
qr/^spam/ => qr/eggs$/,
);
I get:
---
(?-xism:^spam): !!perl/regexp (?-xism:eggs$)
color: red
numbers:
- 5
- 8
Note that the key regex is not explicitly typed. What gives? (Thank!)
source to share
From man perldata
:
Hashes are unordered collections of scalar values, indexed by their associated string key ...
Keys don't have a type in the YAML dump because they don't have a Perl type. They're just strings. In this case, the line(?-xism:^spam)
Try the following:
perl -l -e'%config = ( qr/^spam/ => qr/eggs$/); print $config{"(?-xism:^spam)"}'
source to share