Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Hi, I am new with Perl and Moo. I am trying to pass an array as attributes of a package. I read somewhere that I need to use an array ref. I want it to change the array internally. Specifically, one of the methods will be used to returned an array with one of its element changed. This is for a pacman maze. But I kept getting this error message: isa check for "maze_map" failed: Can't use string ('ArrayRefStr') as a subroutine ref while "strict refs" in use at (eval 18) line 37.

Edit: So this is my mistake. Moo has no isa. Should have checked the documentation first. And also I put Moose in the title. My bad.

Edit2: So I decided to use Moose. I have no problem right now. Will take a look if I can do similar thing like handles => { my_array => 'elements' } in Moo.

package Maze { use Moo; has 'maze_map', is => 'rw', isa => 'ArrayRef[Str]', handles => { m +y_array => 'elements' }, has 'tile_x_dim', is => 'rw', has 'tile_y_dim', is => 'rw', } my @drago = ([1,2,3],[1,3,4]); my $maze = Maze->new( maze_map => \@drago, tile_x_dim => 28, tile_y_di +m => 36 );

In reply to Passing arrayref to Moo attributes by darcrossito

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (9)
    As of 2014-10-22 10:17 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (114 votes), past polls