in reply to Re: Code Works But Not Sure How
in thread Code Works But Not Sure How
I like the idea of using map. I did figure out how I can access the values using:$VAR1 = bless( { 'menu_items' => [ '\'1\'', '\'Option 1\'', '\'2\'', '\'Option 2\'', '\'3\'', '\'Option 3\'', '\'4\'', '\'Option 4\'' ], 'number_of_items' => 8 }, 'MyClass' );
However, I wind up doing this to get single quotes in, but then I have to pass the array size.package MyClass; use strict; use warnings; sub new { my $class = shift; my $self = { number_of_items => shift, menu_items => shift, }; make_menu_items(); bless $self,$class; return $self; } sub make_menu_items { my $items = shift; for (my $i=0; $i < $items->{number_of_items}; $i++) { $items->{menu_items}[$i] = "'$items->{menu_items}[$i]'"; } } 1;
This works more or less. Although I get Use of uninitialized value in numeric lt (<) at MyClass.pm line 20. But It seems like I should be able to get the number of elements in the array in loop through them. What's making it hard for me is making the changes to menu_items instead of @array. Mapping it would be ideal. I could do after declaring the array, but it would sure be nice to do it as part of the calls. Using map would defiantly be cleaner. I'll keep chugging away on it and see what I can come up with. You're close on the purpose of the code. I'm working on some code to work with dialog on Linux boxes. I had written some code a while back, but didn't implement a menubox. Now I have a need for it so I'm trying to finish it. I could probably just use UI::Dialog. But I figure since I'm learning I might as well finish this. Even though probably coded as well as UI::Diaglog.my @array = ("1","Option 1","2","Option 2","3","Option 3","4","Option +4"); my $array_size = @array; my $obj = MyClass->new($array_size,\@array);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Code Works But Not Sure How (updated)
by haukex (Archbishop) on Feb 11, 2018 at 12:36 UTC | |
by RichHamilton (Novice) on Feb 11, 2018 at 13:31 UTC | |
by haukex (Archbishop) on Feb 11, 2018 at 15:14 UTC | |
|
Re^3: Code Works But Not Sure How
by poj (Abbot) on Feb 11, 2018 at 12:49 UTC | |
by RichHamilton (Novice) on Feb 11, 2018 at 13:45 UTC |