Re: multidimensional insertion order



* Spin schrieb:
>
> Alright, let's try again.
> I'm parsing a quasi-xml file into a hash, and here is the code that is
> relevant:

[...]

> tie $xml_lines{$section}->{$section_number}, "Tie::IxHash";

Your $xml_lines{$section}->{$section_number} is just a reference to the
hash. You know about this due to your next line of code:

> $xml_lines{$section}->{$section_number}->{$code_name} = $contents;

You're using Perl's dereferencing operator "->" to access a value of
that reference.

>
> The second tie (in the if statement) is where I get the error "Can't
> locate object method "TIESCALAR" via package "Tie::IxHash" at
> wis_xml_to_html.pl line 56, <XML> line 2."
>
> How do I use Tie::IxHash to maintain the order of insertion in my while
> loop at the {$code_name} level?

Since you don't want to tie a reference [1], you have to tie a hash
instead. Try to dereference the whole hash with "%{}" first:

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

regards,
fabian

[1] A reference is actually stored in a scalar. Thus you get an error
message about "TIESCALAR" (you're trying to tie a scalar and Tie::IxHash
can't do that because it has no mothod named "TIESCALAR"). That's all.
.



Relevant Pages

  • Re: hash two keys to one index
    ... What goes into the map are pairs of (reference to key, ... When I insert an object into the hash table, I pass in ... void insert(Object obj, int hash) throws HashTableFull ... int probe = 0; ...
    (comp.lang.java.programmer)
  • Re: Net::SFTP::Attributes
    ... when I ask a simple question on the correct usage of a module I would ... If $subref is specified, for each entry in the directory, $subref will ... be called and given a reference to a hash with three keys: ...
    (comp.lang.perl.modules)
  • Re: hash two keys to one index
    ... What goes into the map are pairs of (reference to key, ... When I insert an object into the hash table, I pass in ... void insert(Object obj, int hash) throws HashTableFull ... int probe = 0; ...
    (comp.lang.java.programmer)
  • Re: Hashes of Hashes
    ... group = STRING ... If I swap the order of the declarations, then all of the keys for the ... hash that is referenced by $Data. ... This is known as a "symbolic reference" - using the ...
    (perl.beginners)
  • My own handy Pocket Reference notes (please share your own also)
    ... hints/reminders from books and other usenet posts. ... Do you have some handy notes scratched inside YOUR Perl book? ... Here are my personal quick reference notes ... To pass a only single hash to a subroutine: ...
    (comp.lang.perl.misc)