1

Hey im looking at a YML file and i want to to some algorithms and compare values on it but i was wondering what is the best way to do so. I am thinking of creating a lot of objects but I know that can be very inefficient. Is there a way i could just read the YML file one section at a time and make my own methods to compare it?

here is an example of a part of the YML file im working with.

 1:
    type: item
    item:
      material: GRASS
      quantity: 64
    buyPrice: 50
    sellPrice: 5
    slot: 0
  2:
    type: item
    item:
      material: DIRT
      quantity: 64
    buyPrice: 30
    sellPrice: 3
    slot: 1

I need to get Material, Quantity, Buy price, and Sell price. I also will need to compare different "blocks" to other "blocks"

The file can be upwards of 2000 lines and it will change. I do not have to change any part of the file only read.

ThatPurpleGuy
  • 426
  • 7
  • 20

1 Answers1

2

What you need is a YAML Parser/Processor. There are a few libraries that exist that you can use to do this. SnakeYaml seems to be a pretty well known one: https://bitbucket.org/asomov/snakeyaml

Here's another SO post with some more helpful info: Parse a yaml file

Francis Bartkowiak
  • 1,374
  • 2
  • 11
  • 28