Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Setting the value of a complicated hash ref

by blahblah (Friar)
on Dec 30, 2002 at 09:07 UTC ( #223004=note: print w/replies, xml ) Need Help??


in reply to Setting the value of a complicated hash ref

Thank you for all the replies.
I found poj's response very helpful and yet confusing. His code indeed works, but I don't understand why. I am assigning a string to a hash value through a reference. So, in my mind it shouldn't matter what that string happens to be. Instead, poj's code suggests that the carriage return is what is causing the problem of not being able to assign the string. However, the carriage return is already url-encoded before the assignment takes place. (???) Can someone provide an explanation of what is happening here?
pg's 1st point is well taken. I misused the term parser. It is indeed a handler. On your 2nd point: I understand what you are getting at, but not sure if I can get there. My only formal coding instruction has been Turtle Graphics on a 8088 in the 80's. I'm still trying to fully wrap my head around OO. I get it for the most part. However, right now I can drive the car, but I'm still learning how to build the engine. Mabye this is a good opportunity for me. I will investigate separating the filter from the handler (although I'm not quite sure how it could sit -between- the parser and handler; I would think the handler would call it out during processing events - which I guess is how I have it now...hmm...?)
First, thanks for the XML::SAX module Matts. However, the code you pointed out I don't believe to be the problem since earlier in the code I do:
$pos[$depth] = \$data{$id_attribute};

The correct dereference to get the value of that hash key should be:
print "${$pos[$depth]}\n";

Am I wrong here?

Again, thanks everyone, I'm learning a lot with this one.

Thanks,
Alex

Replies are listed 'Best First'.
Re: Re: Setting the value of a complicated hash ref
by poj (Abbot) on Dec 30, 2002 at 10:17 UTC
    I think the reason my fix works is this;
    You are building a HOH by adding to it at each start_tag here -
    $pos[$depth] = \${$pos[$depth - 1]}->{$element->{Name}};
    If later, you allow a text string to be assigned to $pos[$depth] then at the next depth the program fails because \${$pos[$depth - 1]} is now not a hash reference.
    The text string should only be assigned when you reach the lowest level. In your XML data this conveniently is when there are no line breaks in the data. This is a big assumption and I would not do this for a serious application - much better to use the proper tools.
    Hope this helps, I too am learning from this
    poj

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://223004]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2020-07-02 05:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?