Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (7)
    As of 2018-06-20 06:25 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (116 votes). Check out past polls.