Skip Menu |

This queue is for tickets about the Term-Menus CPAN distribution.

Report information
The Basics
Id: 62433
Status: resolved
Worked: 4 hours (240 min)
Priority: 0/
Queue: Term-Menus

People
Owner: Brian.Kelly [...] fullautosoftware.net
Requestors: MTHURN [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.57
Fixed in: 2.32



Subject: return the item number rather than name
It would be nice if there were a way to get the item number (array index) of the user's choice, rather than its text value.
On Mon Oct 25 10:18:41 2010, MTHURN wrote: Show quoted text
> It would be nice if there were a way to get the item number (array > index) of the user's choice, rather than its text value.
Hi Kingpin ;-) It's not surprising someone would ask for this eventually. There are a few issues with this request, but I will put it on the to-do list. For one, if all you want is a simple one-level no frills menu, then use &pick rather than &Menu. I will implement the third argument as an index_flag ( to &pick() )that will force the return of the index rather than the text string (future functionality - not yet implemented). &Menu is a bit trickier, because options are configured in the hash block, not the parameter arguments. I will implement this when I get a chance: use strict; use Term::Menus; my @list=('One','Two','Three'); my %Menu_1=( Item_1 => { Text => "]Convey[", Convey => \@list, Result => "Index" }, Select => 'One', Banner => "\n Choose a /bin Utility :" ); my @selections=Menu(\%Menu_1); print "\nSELECTIONS = @selections\n"; ### Note the "Index" with the Result key. ### BUT ### You don't have to wait, you can get what you need with the latest version of Term::Menus (I am uploading it later today - 1/23/2011. Will be available via CPAN utility 1/24/2011 after 9:00am EST). Just use this instead: use strict; use Term::Menus; my @list=('One','Two','Three'); my %Menu_1=( Item_1 => { Text => "NUMBER - ]Convey[", Convey => \@list, Result => sub { my $cnt=-1;my $selection=']Selected['; foreach my $item (@list) { $cnt++; chomp($item); last if -1<index $selection, $item; } return "$cnt"; } }, Select => 'One', Banner => "\n Choose a /bin Utility :" ); my @selections=Menu(\%Menu_1); print "\nSELECTIONS = @selections\n"; ################ The latest major addition to Term::Menus is the ability to use macros in anonymous subroutines that can be fed to either the Convey or Result elements of the Menu hash. With this new capability, the ability to manipulate data and carry it through an endless variety of Menu transformations is practically UNLIMITED.
Documentation for Term::Menus has been updated to include code that accomplishes the request for which this ticket was created.