Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
1Nickt You're right I did go back at the data dumper and I see what you're talking about. What it should show is:
$VAR1 = bless( { 'menu_items' => [ '\'1\'', '\'Option 1\'', '\'2\'', '\'Option 2\'', '\'3\'', '\'Option 3\'', '\'4\'', '\'Option 4\'' ], 'number_of_items' => 8 }, 'MyClass' );
I like the idea of using map. I did figure out how I can access the values using:
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;
However, I wind up doing this to get single quotes in, but then I have to pass the array size.
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);
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.

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

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!
  • 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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (3)
    As of 2018-07-21 12:05 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      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.

      Notices?