Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How do I work with multidimensional arrays in Moose?

by glasswalk3r (Pilgrim)
on Sep 03, 2013 at 14:38 UTC ( #1052117=note: print w/ replies, xml ) Need Help??


in reply to How do I work with multidimensional arrays in Moose?

First, I would recommend using <readmore> tags around your code section, long posts make it difficult to get help.

Regarding your question, I believe Moose does not have anything related to your task at hand but I may be wrong. Did you try searching CPAN first?

Anyway, you should use "regular" code to deal with your array references. Moose will help you only with the type checking that you used when creating the attribute. Create methods to deal with the array references, and just be sure to assign the proper value when writing back to the attribute.

Anyway, since you're dealing with references, you could change the data inside it without accessing the attribute anyway, but this might be dangerous if done outside the class methods.

Looks like that you're expecting Moose to validate the data, but to have that you would need to invoke the set or whatever you have defined as writer for the arr2d attribute.

If you're not trying to improve performance by using array references, I would suggest you to create classes to represent the data structure that you want instead of plain data. That would help using an easier way to change data inside the structure and being able to check for problems during the process.

I would also suggest you to choose better names for the attribute and methods, but maybe you're justing experimenting.

Alceu Rodrigues de Freitas Junior
---------------------------------
"You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill


Comment on Re: How do I work with multidimensional arrays in Moose?
Select or Download Code
Re^2: How do I work with multidimensional arrays in Moose?
by paulymer (Novice) on Sep 03, 2013 at 22:50 UTC

    Thank you for the suggestions, glasswalk3r. I have added the <readmore> tags; much better, I agree. Yes, I was expecting Moose to validate the data, but obviously I've not constructed the class correctly for Moose to do that. An example of how to do this would be very helpful.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2014-08-30 13:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls