Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6350837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:53:15+00:00 2026-05-24T21:53:15+00:00

I want to read data from a YAML file but I need the order

  • 0

I want to read data from a YAML file but I need the order of the elements to be preserved.

Is there a module in perl which has this functionality and how to do that?


In response to @mugen kenichi

I managed to do what I want but I don’t believe that this is a reasonable solution.

old YAML:

foo:
   bar: some value
   baz: other value
qwe:
   bar: yet another value
   baz: again

new YAML

 -
   foo:
      bar: some value
      baz: other value
 -  
   qwe:
      bar: yet another value
      baz: again
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:53:15+00:00Added an answer on May 24, 2026 at 9:53 pm

    UPDATE: YAML.pm now supports order preservation. See this up-to-date answer.

    The YAML spec specifically states that "mapping keys do not have an order" and that "in every case where node order is significant, a sequence must be used". To infer order from a mapping would be in violation of the spec. Using ordered mappings, as mentioned by mugen, is the correct solution to preserve order.


    If you *really* wanted to, you could somehow get a YAML parser to dump into a [Tie::IxHash][2] which will preserve order… but I know of no Perl YAML parser which gives you that level of control. It’s possible you could do something with [YAML::Old::Loader][3], but that is not a very good YAML parser and YAML::Old::Loader is not documented.

    A third option would be to use explicit YAML tags (aka types) to instruct the parser to load your mappings as a special type and then you supply the callback… but even then it’s likely the YAML parser will supply your callback with an unordered hash.

    I would suggest you simply change the YAML. The point of a portable data language is that all the semantic meaning is explicit in the data file or the spec, not implicit in a particular parser. Ordered mappings are an accepted, compact YAML idiom.

    - foo:
          bar: some value
          baz: other value
    - qwe:
          bar: yet another value
          baz: again
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read data from a XMl file which is in a predefined
I want to read data about MMORPG characters from a .txt file and then
I want to read data from a website with cURL but from a certain
I want to read data from a CFG (configuration file). How do I read
I am about to read data From a File which has stored it's time
I am new to C, and want to read some data from a file.
Is there a way I can read data from a file until a space?
i want read data from the binary file named xyz.bin and want to parse
I'm trying to read data from the WMI Win32_NTLogEvent class, but I only want
I want to read data from a CSV file using microsoft text driver. Can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.