Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
The main issue is that your array is not passed to the subroutine, since you give no arguments in the call.

RichHamilton: I just wanted to highlight this since it is the first thing that jumped out at me when I skimmed your code.

Inside new, you call make_menu_items();, without arguments and not as a method call, so Perl won't pass $self as the first argument. One way to change this is by blessing the object first, i.e. bless $self, $class; $self->make_menu_items();.

So in the code you showed, in the call to sub make_menu_items, $self starts out as undef. The reason the code doesn't fail is autovivification (here's one thread of several on that). As 1nickt said, if you dump $self, you'll see that before the line "my $items = $#{$self->{menu_items}};" it is undef, but after that line it magically becomes { menu_items => [] }, because you first accessed it as a hashref with $self->{...}, and then accessed the hash key menu_items as an array reference with $#{...}.

In reply to Re^2: Code Works But Not Sure How by haukex
in thread Code Works But Not Sure How by RichHamilton

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 romping around the Monastery: (3)
    As of 2018-07-21 11:59 GMT
    Find Nodes?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

      Results (448 votes). Check out past polls.