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.
  • Color me stupid, but what's wrong with it? Or, put another way, what structure are you trying to express?
    • What's wrong with what? If you mean the even-sized list, that should actually be an ordered list of pairs. That's something which Perl 6 can express, but not Perl 5 (at least, not cleanly). As a result, I need an even-sized list in the correct format (which sucks), or a list of hashes, each of which only has one key/value pair. I expect I'll go with the latter.

      Or were you referring to something else?

      • I'm unable to envision the structure you're trying to express. I don't understand how the XML and the two YAML snippets relate to each other.

        Some of the assertions confuse me because they seem to be wrong. Like "YAML doesn't really support the idea of an array of pairs or ordered hashes". They address this specifically in the spec [yaml.org]. Wouldn't an array of pairs be:

            - key:   value
            - this:  that
            - up:    down
        And why does it need to be ordered?

        If you can show me what you'd like to express, in some made-up magic formatting language, I think I can show you how to express it in YAML. I'm going to take a stab and say you want this:

        elements:
          - name:
              type: string
              attributes:
                some_attr:
                    method: dummy_attribute
          - email*:
              type: string
          - phone+:
              method: phone_numbers
              type: string
          - active:
              data: yes
        That's assuming the * and + things are part of the actual key name. It translates into:

        {
          'elements' => [
            {
              'name' => {
                'type' => 'string',
                'attributes' => {
                  'some_attr' => {
                    'method' => 'dummy_attribute'
                  }
                }
              }
            },
            {
              'email*' => {
                'type' => 'string'
              }
            },
            {
              'phone+' => {
                'type' => 'string',
                'method' => 'phone_numbers'
              }
            },
            {
              'active' => {
                'data' => 'yes'
              }
            }
          ]
        };
        If you can drop the ordering requirement it becomes even simpler:

        elements:
           name:
              type: string
              attributes:
                some_attr:
                    method: dummy_attribute
           email*:
              type: string
           phone+:
              method: phone_numbers
              type: string
           active:
              data: yes
        which translates to

        {
          'elements' => {
            'active' => {
              'data' => 'yes'
            },
            'name' => {
              'type' => 'string',
              'attributes' => {
                'some_attr' => {
                  'method' => 'dummy_attribute'
                }
              }
            },
            'phone+' => {
              'type' => 'string',
              'method' => 'phone_numbers'
            },
            'email*' => {
              'type' => 'string'
            }
          }
        };