views:

199

answers:

1

This relates to a previous question: How can I read Perl data structures from Python?. It could be a bug in the version of the YAML parser that I'm working with (0.66), but when I run:

perl -MYAML -le 'do shift; print YAML::Dump( $CPAN::Config )' simple.pl

On 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 doesn't have the explicit type. What gives? (Thanks!)

+4  A: 

From man perldata:

Hashes are unordered collections of scalar values indexed by their associated string key.

The keys don't have a type in the YAML dump because they don't have a type in Perl. They are just strings. In you case the string (?-xism:^spam)

Try this: perl -l -e'%config = ( qr/^spam/ => qr/eggs$/); print $config{"(?-xism:^spam)"}'

mirod
Excellent reason! :-) I figured they were just immutable objects - my brain gets stuck in Python land sometimes.
cdleary