CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Traveling on a complex object

 



zatlas1
User

Dec 10, 2014, 8:38 PM

Post #1 of 7 (6026 views)
Traveling on a complex object Can't Post

I have a structure like the attached (It is an output from MarpaX package). which is a Dumper of the result of this accessor:
my $valueref = $re->value()
With my limited knowledge, I do not know how could I travel on that object to extract, let's say the tuples that belong to all blessed objects of the type 'MarpaX::Languages::SQL::AST::columnDefinition'... in essence, extract all the column names.

Thanks
ZA
Attachments: value1.txt (160 KB)


Laurent_R
Veteran / Moderator

Dec 10, 2014, 11:36 PM

Post #2 of 7 (6015 views)
Re: [zatlas1] Traveling on a complex object [In reply to] Can't Post

The standard way to access to the inner components of an object is to use the accessor methods of that object's class (or parent classes). Please check the documentation for your object's class.

It is possible in Perl to access directly to the inner components, but this is really not the recommended course of action, because it will fail once the inner implementation of the object will change, whereas the interface (accessor methods) should continue to work.


zatlas1
User

Dec 11, 2014, 3:08 AM

Post #3 of 7 (6011 views)
Re: [Laurent_R] Traveling on a complex object [In reply to] Can't Post

OK, I know that...
Basically, in my case, I need to code the accessor and I ask for basic help on how to do that
ZA


(This post was edited by zatlas1 on Dec 11, 2014, 3:52 AM)


FishMonger
Veteran / Moderator

Dec 11, 2014, 6:18 AM

Post #4 of 7 (5974 views)
Re: [zatlas1] Traveling on a complex object [In reply to] Can't Post

So, you're looking to extend the module?

The starting point would be to analyze the source code to learn how the object is built. That will give you a deeper understanding than simply dumping the data structure.


zatlas1
User

Dec 11, 2014, 7:29 AM

Post #5 of 7 (5947 views)
Re: [FishMonger] Traveling on a complex object [In reply to] Can't Post

Please, I have a brain dead day. I do not need to extend the module, I just get this object and need to code a specialized accessor that would give me what I need.
I cannot recall how to approach it code wise. All I ask is the first basic lines of code that would allow me to access the object. I will do the rest of the work myself and return objects or values as necessary.
Thanks
ZA


FishMonger
Veteran / Moderator

Dec 11, 2014, 8:45 AM

Post #6 of 7 (5928 views)
Re: [zatlas1] Traveling on a complex object [In reply to] Can't Post

What you're asking has nothing to do with writing "a specialized accessor". You're asking about how to de reference a multi-dimensional array.

If you know the exact array level you need to access, then you can simply access it directly. Otherwise you would use a nested loop to traverse the array.

Doing this on a blessed object instead of using an accessor method provided by the module's API is considered a very poor practice. If the author of the module didn't provide that method, then the proper thing to do is to either extend the module yourself by writing/adding that method to the module (or your subclass) or to ask the author to add that interface in the next release.


zatlas1
User

Dec 11, 2014, 9:11 AM

Post #7 of 7 (5915 views)
Re: [FishMonger] Traveling on a complex object [In reply to] Can't Post

Thank you
Now I remember how to do that. I can code the accessor(s) and either extend the module or use it in my specialized module.
ZA

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives