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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |