【发布时间】:2016-05-25 20:15:30
【问题描述】:
我有大量数据保存为 Data::Dumper 输出。
我到底应该如何读取这些数据?我想重新组织它,但我完全迷失了这种方法。数据结构是数组中的哈希,是哈希的哈希......
这是一个(非常精简的)示例。此外,创作也不是很好,因为一个角色可以有两次“攻击”或两次“特殊”,所以很明显这是一次碰撞,一个会被覆盖。
编辑:我真正要问的是:这是存储此类数据的理想方式吗?或者,还有更好的方法?因为对我来说访问像$char_hash{Character Name}{abilities}{attack}{tiers}{level 1}{description} 这样的散列看起来很糟糕。遍历@{$char_hash{Character Name}{Equipment}{Equipment Level 1}{Items}} 之类的东西似乎非常困难
my @char_hash = (
"Character Name" => {
"description" => "",
"alignment" => "",
"categories" => [
"ex 1",
"ex 2",
"ex 4",
"ex 5"
],
"primaryStat" => "Strength (STR)",
"baseStats" => {
"Strength (STR)" => "22",
"Agility (AGI)" => "15",
"Intelligence (INT)" => "17",
"Speed" => "100",
"Health" => "197",
"Physical Damage" => "17"
},
"abilities" => {
"attack" => {
"name" => "ex 1",
"type" => "Physical",
"tiers" => {
"level 1" => {
"description" => ""
},
"level 2" => {
"unlockLevel" => 16,
"cost" => {
"Money" => 700,
"Material" => 3
},
"fromPrevious" => "+5% Damage",
"description" => ""
}
},
"conditions" => {
}
},
"special" => {
"name" => "ex",
"cooldown" => 3,
"type" => "special",
"tiers" => {
"level 1" => {
"description" => ""
},
"level 2" => {
"unlockLevel" => 18,
"cost" => {
"Money" => 1300,
"Material" => 2
},
"fromPrevious" => "+5% Damage",
"description" => ""
}
},
"conditions" => {
}
},
"Equipment" => {
"Equipment Lvl I" => {
"cummulatedStats" => {
"Strength (STR)" => "+22",
"Agility (AGI)" => "+15",
"Intelligence (INT)" => "+17",
"Speed" => "+100",
"Health" => "+197",
"Physical Damage" => "+17"
},
"items" => [
{
"name" => "",
"id" => "",
"tier" => 1,
"mark" => "",
"requiredLevel" => 1,
"sellValue" => 10,
"stats" => {
"Physical Damage" => ""
}
},
{
"name" => "",
"id" => "",
"tier" => 1,
"mark" => "",
"requiredLevel" => 2,
"sellValue" => 20,
"stats" => {
"Strength (STR)" => "",
"Agility (AGI)" => "",
"Intelligence (INT)" => ""
}
},
{
"name" => "",
"id" => "",
"tier" => 1,
"mark" => "",
"requiredLevel" => 2,
"sellValue" => 20,
"stats" => {
"Strength (STR)" => "",
"Agility (AGI)" => "",
"Intelligence (INT)" => ""
}
},
{
"name" => "",
"id" => "",
"tier" => 1,
"mark" => "",
"requiredLevel" => 2,
"sellValue" => 20,
"stats" => {
"Speed" => ""
}
},
{
"name" => "",
"id" => "",
"tier" => 1,
"mark" => "",
"requiredLevel" => 2,
"sellValue" => 20,
"stats" => {
"Strength (STR)" => ""
}
},
{
"name" => "",
"id" => "",
"tier" => 1,
"mark" => "",
"requiredLevel" => 2,
"sellValue" => 20,
"stats" => {
"Armor" => ""
}
}
]
}
}
}
}
);
【问题讨论】:
-
问题是什么?就目前而言,这篇文章太宽泛,没有用处。
-
我编辑了原帖
-
您的编辑几乎使问题变得更糟,因为现在任何答案都是意见而不是事实。
-
没关系。我会听取意见的。现在组织和访问数据似乎令人生畏。你会怎么做?
-
不,我想你不明白。主要基于意见的问题不被视为on-topic for Stack Overflow,可能会被关闭。
标签: perl data-structures