Re: multidimensional insertion order



Spin <cNaOlSePbA@xxxxxxxxxxxxxxxxxx> wrote:
> Paul Lalli wrote:
> > You're attempting to tie a reference to a hash to the Tie::IxHash
> > class. A reference is a scalar. Therefore, tie() is attempting to use
> > a non-existant TIESCALAR method.
> >
> > You *want* to tie the hash that that reference references to the
> > Tie::IxHash class.
> >
> > Try: (untested)
> >
> > tie %{$xml_lines{$section}->{$section_number}}, "Tie::IxHash";
> >
> >
> That truncates the hash somehow.

When you tie a hash to Tie::IxHash, it empties the hash (which makes sense,
as what else is it going to do with pre-existing, and hence generally
unordered, data?).

You are retying the hash each time through the loop, and so re-emptying it
each time and are left only with the last thing inserted. You want to
detect whether the subhash already exists and then create and tie it only
if it doesn't already exist.

unless ($xml_lines{$section}->{$section_number}) {
tie %{$xml_lines{$section}->{$section_number}}, "Tie::IxHash";
};

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
.



Relevant Pages

  • Re: Help with tied/nested data structures
    ... tie %hash, 'HashTest'; ... package ScalarTest; ... sub FETCH { ... tie $$ref, 'ScalarTest', $value; ...
    (comp.lang.perl.misc)
  • DB_File and File Locking -- Best Practices
    ... I am am unluckily stuck with a slow moving IT department managing the ... Traditionally file locking was supposed to go like this: ... when you tie the %hash the file is read before the lock is made. ...
    (comp.lang.perl.misc)
  • Re: FAQ 4.61 How can I always keep my hash sorted?
    ... perl's own hash implementation copied from the guts and put into a tie able ... In older versions of perl, ... there were a fixed list of possible vtables, ...
    (comp.lang.perl.misc)
  • Re: Help with tied/nested data structures
    ... You aren't having a problem with the GC culling them now. ... uses a normal hash to store values. ... scalar is stored as such and not, for instance, stringified. ... Some tie classes do that. ...
    (comp.lang.perl.misc)
  • Re: using Hash::Case and Storable
    ... > I'm using the Storable module to save and load a hash tree. ... You need to tie your hash after retrieving the values. ... hashref as the 'VALUES'. ...
    (perl.beginners)