mgwmgw has asked for the wisdom of the Perl Monks concerning the following question:

I am writing tests in perl 5.10.1 of a part of a product written in python 2.6.6.

The python, which I think is using PyYAML, outputs YAML which is acceptable to pylint, but not acceptable to the YAML Loader in perl. I find multiple different examples of this. I think the perl is using YAML::Old.

I suspect that the best solution would involve moving to a newer YAML Loader in perl, but I seek advice about which one. The PyYAML port to perl supposedly is not finished yet.

Thanks.

  • Comment on python YAML output, perl Loader, which version?

Replies are listed 'Best First'.
Re: python YAML output, perl Loader, which version?
by davido (Cardinal) on Apr 16, 2014 at 17:41 UTC

    I think it would be easier to provide a good response to this question if you provide us with an example of some YAML input that is not parsing correctly using a Perl YAML module, and then an example of the desired output. I don't know anything about PyYAML, and I've got plenty of other priorities on things I am interested in learning without spending time with it. Sample input, expected output, and actual output will save us research time by allowing us to leverage what you already know, adding to it those things that we already know.


    Dave

Re: python YAML output, perl Loader, which version?
by stonecolddevin (Parson) on Apr 16, 2014 at 17:42 UTC

    It would be super helpful if we could see an example of the YAML being generated. YAML is YAML, if it's adhering to the YAML standard, there's no reason it can't be parsed by *any* YAML parser that also adheres to said standard.

    Three thousand years of beautiful tradition, from Moses to Sandy Koufax, you're god damn right I'm living in the fucking past

      Here is an example of a string I created in perl that reproduces one of the problems:

      $out = "Things:\n - Name: thing_1\n Sub:\n key1: value1\n + key2: very very very very very very very very very very very very + very very\n long line wrapped value2\nkey3: value3\n";

      When it prints out in the log, it looks like this:

      Things: - Name: thing_1 Sub: key1: value1 key2: very very very very very very very very very very very ver +y very very long line wrapped value2 key3: value3

      If I paste this into yamlint it is valid, but the Loader complains:

      YAML Error: Inconsistent indentation level

        You want this?

        #!/usr/bin/perl -- use strict; use warnings; use YAML qw/ Load Dump /; use Data::Dump qw/ dd /; my $it = { Things => [ { Name => "thing_1", Sub => { key1 => "value1", key2 => "very very very very very very very very very +very very very very very long line\nwrapped value2", key3 => "value3", }, }, ], }; dd( Dump( $it ) ); print Dump( $it ), "\n"; __END__ "---\nThings:\n - Name: thing_1\n Sub:\n key1: value1\n +key2: |-\n very very very very very very very very very very v +ery very very very long line\n wrapped value2\n key3: val +ue3\n" --- Things: - Name: thing_1 Sub: key1: value1 key2: |- very very very very very very very very very very very very ve +ry very long line wrapped value2 key3: value3
        How did you create the string? Why is your indentation level inconsistent? Perl module YAML also complains
        YAML Error: Inconsistent indentation level Code: YAML_PARSE_ERR_INCONSISTENT_INDENTATION Line: 6 Document: 1