On Tuesday, Nov 25, 2003, at 05:11 US/Pacific, [EMAIL PROTECTED] wrote:
Hi im am trying to build a menu. and i wont to load files into this menu dynamic. As base i use Term_ANSIMenu-0.02 This module builds a meny from sub function called items. What i wont to do is build syb function item dynamaic.
Is there anyone who don this before. ????
actually no, it has been a long time since I worried about such things. So bear with me a bit, since this means reading the POD
<http://search.cpan.org/~jadev/Term-ANSIMenu-0.02/ANSIMenu.pm>
based upon the illustrative code
use Term::ANSIMenu;
my $menu = Term::ANSIMenu->new(
width => 40,
help => [['', \&standard_help],
['hint 1', \&help_item],
[ undef, \&standard_help],
['hint 3', undef]
],
title => 'title',
items => [['1', 'First menu item', \&exec_item],
['2', 'This string is just too long \
to fit in a normal terminal \
and thus it will be clipped.'],
['3', '', sub { system "man man" }]
],
status => 'status',
prompt => 'prompt: ');
The part that you want to have as a 'dynamic' bit is that section for 'items', yes? Hence it would seem that all we need to do is have an array reference that would be say
items => $item_list,
where we had previously solved
my $item_list = [['1', 'First menu item', \&exec_item],
['2', 'This string is just too long \
to fit in a normal terminal \
and thus it will be clipped.'],
['3', '', sub { system "man man" }]
];
eh no? Which is really merely an array of array references? Which apparently is of the form:
<index_num> , <prompt> , <code_ref>
So if you want to make a dynamic menu, clearly all you need to do is solve what goes into each of those three things for each menu item?
But it is this part where you want to 'load files' that I think is your issue? Not the simpler problem of how do I dynamically make an array of array references?
So a way of looking at that might be something like:
#------------------------
#
sub exec_item
{
my ($filename) = (@_, 'NoNameHere');
print "Welcome to Exec_item - with $filename\n";
} # end of exec_item
#------------------------
#
sub gen_menu
{
my ($file_list) = @_;
my $i = 1;
my $array_ref = [];
foreach my $file (@$file_list)
{
push(@$array_ref , [ $i++ , "view $file ", sub { exec_item($file) } ]);
}
$array_ref;
} # end of gen_menu
#
# the main loop
#
my @list_oh_files = qw /bob ted carol alice/;
my $item_list = gen_menu([EMAIL PROTECTED]);
foreach my $entry (@$item_list)
{
print "item $entry->[0] says $entry->[1]\n";
&{$entry->[2]}() if( scalar(@$entry) > 2);
}
HTH...
ciao drieux
---
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]