http://www.perlmonks.org?node_id=1015745


in reply to Strange YAML behavior with lists of qr regexp values

It doesn't seem to have anything to do with the adding of new patters.

Instead, YAML::Syck's LoadFile() function seems to always add a level of brackets around all regexes it reads from a YAML file, even if they already have outer brackets.

Example:

test-re.pl:

#!/usr/bin/perl use strict; use warnings; use YAML::Syck qw(LoadFile); use Data::Dumper; my $yaml = LoadFile( 'test-re.yaml' ); print Dumper($yaml->{patterns}), "\n";

test-re.yaml:

--- patterns: - !!perl/regexp (?^i:^foo.*bar.*baz) - !!perl/regexp ^quux$

Output:

$VAR1 = [ qr/(?^:(?^i:^foo.*bar.*baz))/, qr/(?^:^quux$)/ ];

Output when changing use YAML::Syck to use YAML:

$VAR1 = [ qr/(?^ui:^foo.*bar.*baz)/, qr/(?^u:^quux$)/ ];

So yeah, seems to be a YAML::Syck particularity. Whether it is a bug is a matter of opinion I guess, since the regexes do behave the same so nothing should break.

Replies are listed 'Best First'.
Re^2: Strange YAML behavior with lists of qr regexp values
by naChoZ (Curate) on Jan 30, 2013 at 15:06 UTC

    I notice that YAML::XS is similarly affected. Storing regular expressions themselves obviously must not be on too many radars. ;)

    --
    Andy