package Menu; use strict; use Data::Dumper; sub new { my ($self, %args) = @_; bless { _title => $args{title} || die "Sorry, we need a title for this menu!", _header => $args{header}, _comment => $args{comment} }, $self; } sub set_choices { my ($self, %choices) = @_; my $count; foreach (keys %choices) { $self->{$_} = ( _id => $_, _name => $choices{$_}{name} || die "Sorry, we need a name for this menu entry!", _sub_or_id => $choices{$_}{sub_or_id} || 0, _return_sub => $choices{$_}{return_sub} ); } } sub print { my $self = shift; print Dumper $self; } 1; #### #!/usr/bin/perl # test_menu.pl use strict; use lib qw(.); use Menu; my $menu = Menu->new( title => "Testing menu", header => "Just testing...", comment => "Ok, this is where the comment section would normally go." ); my %entries = ( 1 => { name => "Entry #1" }, 2 => { name => "Entry #2" }, 3 => { name => "Entry #3" }, 4 => { name => "Quit" } ); $menu->set_choices(%entries); $menu->print; #### [jason@lappy jason]$ perl test_menu.pl $VAR1 = bless( { '1' => 'Entry #1', '2' => 'Entry #2', '3' => 'Entry #3', '4' => 'Quit', '_title' => 'Testing menu' }, 'Menu' );