Re: A good data structure to store INI files.
- From: Marc Lucksch <perl@xxxxxxxxx>
- Date: Tue, 10 Feb 2009 20:12:07 +0100
Marc Lucksch schrieb:
Maybe I'm an idiot here, but I can't figure this one out even if my life would depend on it:Maybe I posted the question wrong, it is not about the INI parsers, I just didn't want to release another one...
Lets say I have this data structure, from an ini file, it cares for all the conditions that can happen (multiple sections, keys and values)
my $ini={
Ship=>[
{#First Ship
nickname=>[ #A key
['li_elite'] # value
],
fuse=>[ #multikey with multivalue
['intermed_damage_smallship01','0.000000','400'],
['intermed_damage_smallship02','0.000000','200'],
], #....
},{#Second Ship
nickname=>[
['li_elite2']
],fuse=>[
['intermed_damage_smallship01','0.000000','400'],
['intermed_damage_smallship02','0.000000','200'],
], #....
}, #A lot more 'Ships'
],Simple=>[
#A lot of Simples
],ship=>[
# 3 or 4 ships, sometime they are lowercase...
# That's a problem with this data model,
# Can't use Hash::Case::Preserve either,
# cause I would loose which ship's which.
],Pilot=>[
{
name=>[['pilot_corsair']],
}#Just one pilot entry
],
# lot more sections....
}
1. Problem:
I can't save the order the sections or keys came in, nor the names of them so I can't write an unmodified file out again. I would have to tie that structure.
I want to make is easily accessable:
$ini->{Pilot}->{name} instead of:
$ini->{Pilot}->[0]->{name}->[0]->[0].
for (@$ini) {
#in the order they came in, because a section can affect the
#following one. As seen in weapon_equip.ini, where [LODsomething.]
#before [Gun] affects the Gun LODs, I can't mix those up.
}
for (@{$ini->{Ships}}) {
#Return ships in order of appearance.
}
But I would need overload for that, and I could save it into an array for the order and a hash for quick lookup.
But I can't just return a hash with overload, because it wouldn't change my array on operations like
delete $ini->{newvalue}; (Change in array missing.
for (0 .. $#{$ini}) {
delete $ini->[$_] if something($_); #Change in Hash missing.
}
Which one do I trust now, hash or array?
or even
delete $ini->{Pilot};
$ini->{Pilot}=$otherpilot. #Order destroyed.
So I would have to return a tied hash, which gives me a lot of trouble with overload again. (See perldoc overload, last section or so)
.... No solution :( ...
Either I need a better way to save it, or I'm missing something here?
Marc "Maluku" Lucksch
.
- Follow-Ups:
- A problem with TIEHASH [was: A good data structure to store INI files.]
- From: Marc Lucksch
- Re: A good data structure to store INI files.
- From: sln
- A problem with TIEHASH [was: A good data structure to store INI files.]
- References:
- A good data structure to store INI files.
- From: Marc Lucksch
- A good data structure to store INI files.
- Prev by Date: Re: A good data structure to store INI files.
- Next by Date: Re: A good data structure to store INI files.
- Previous by thread: Re: A good data structure to store INI files.
- Next by thread: Re: A good data structure to store INI files.
- Index(es):
Relevant Pages
|
Loading