Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I think you have misunderstood the specs because you are getting the expected behaviour.

    You are interested in the value of the "optional_features" key, and you expect that to be a ref to a list of two elements: the first element is "foo"; the second is a ref to a hash of the other data.

    When you describe what you want you can see that the list has 2 elements. So in YAML you need one "-" for each element. So what you want is:

        optional_features:
            - foo
       
    • Actually, you need to *correct the indentation*.  (Why does this site screw with my indentation in plain text?  Yes, I should use "preview".  I'm now using "code")

      *This* is what you want:

      optional_features:
        - foo
        - description: test
          requires_os: Linux
          requires:
            Test::More: 0.47

      • Except it isn't ;)

        optional_features is a list, with each element of the list being a map with an identifier. The indentation I'd used made it look like the list element had no identifier, hence why 'foo => undef' existed inside the map, when I meant for it be the identifier for the map. ferreira [perl.org] has put me on the right track.

        As I suspected, I had just misunderstood the specs, as I didn't think I could have been the first person to come across this.

        As for indenting in use.perl, you want '<ecode>'

        • Are you sure it isn't what you want?  I'm trying to understand what you are describing.

          You say "each element of the list being a map with an identifier".  That is possible in Perl6, but in Perl5 a list (or array) element can only be a simple scalar or a reference to something.

          So I think you must mean that you want a list that looks something like this:  [ foo => { ... } ]

          Is that what you want?

          That list has 2 elements: the first is "foo"; the second is a hashref.

          In your initial post you said you expected

          'optional_features' =>
            [
              'foo' => {
                'description'       => 'test',
                'requires_os'       => 'Linux',
                'requires'          => { 'Test::More' => '0.47' },
             }
            ],

          as your resulting data structure.  That is exactly what is produced by my YAML:

          optional_features:
            - foo
            - description: test
              requires_os: Linux
              requires:
                Test::More: 0.47

          Try it.