PilotinControl has asked for the wisdom of the Perl Monks concerning the following question:

Hello Fellow Monks,
I have a flat file filled with several fields and a script that can view all the fields in a formatted order. What I would like to do is be able to select a row by using the arrow keys and when I press enter I can view that row in a formatted view and be able to edit each field. I have looked at the Term::Menus module as it has the select option I am searching for. Any examples out there I can view that has what I'm searching for? Also if any perl programmer out there is looking for some part time work please private message me. Thanks!

Replies are listed 'Best First'.
Re: Perl Menus
by zentara (Cardinal) on Sep 30, 2014 at 21:33 UTC
    Does your program need to be terminal based or can you use an graphical gui? For instance, if you can use Gtk2, you can do something like this.
    #!/usr/bin/perl -w use strict; use Gtk2 -init; use Gtk2::SimpleList; # by muppet on gtk-perl maillist my $window = Gtk2::Window->new; $window->signal_connect (destroy => sub { Gtk2->main_quit }); my $hbox = Gtk2::HBox->new; $window->add ($hbox); my $s1 = Gtk2::SimpleList->new ( 'Number' => 'int', 'Function' => 'text', 'Default' => 'int', 'Subvalues' => 'scalar', ); # Hide the Subvalues column. This will remove it from the treeview, # not from the model. One alternative to this is to use a column of # SimpleList type 'hidden', but that creates a column which only holds # text strings. Yet another alternative is to create a new SimpleList # column type for holding scalars in a hidden column... but this is # easier. :-/ $s1->remove_column ($s1->get_column (3)); my $s2 = Gtk2::SimpleList->new ( 'Value' => 'int', 'Midpoint' => 'int', 'Description' => 'text', ); @{ $s1->{data} } = ( [1, 'Volume', 0, make_sub_list ([ 32, 128, 'Preset1'], [ 220, 128, 'Preset2'])], [2, 'Pan', 128, make_sub_list ([ 64, 128, 'position in the stereo field'])], [3, 'Treble', 128, make_sub_list ([196, 128, 'high frequencies'])], [4, 'Mid', 128, make_sub_list ([157, 128, 'midrange frequencies'])], [5, 'Bass', 128, make_sub_list ([200, 128, 'low frequencies'])], [6, 'Color1', 128, make_sub_list ([10,5,'White'],[20,15,'Blue'])], [7, 'Whee', 255, make_sub_list ([10,5,'Ready'],[15,20,'Set'], [42,-1,'Go'])], ); $hbox->add ($s1); $hbox->add ($s2); $s1->get_selection->signal_connect (changed => sub { my ($selection) = @_; my $slist = $selection->get_tree_view; my ($sel) = $slist->get_selected_indices; # Here's something a little bit evil... we've stored the subvalues # as the TiedList objects that SimpleList uses. However, we need the # underlying ListStore for the TreeView. The ListStore is stored in # the TiedList object, so we have to get to that with tied(). Note # that we had a reference to the tied object, so we have to # dereference that when calling tied(), or it doesn't work. my $tiedlist = $slist->{data}[$sel][3]; $s2->set_model (tied(@$tiedlist)->{model}); # If you actually want to be able to use $s2->{data}, we have to # update it separately. Perhaps we should override set_model() # on SimpleList? $s2->{data} = $tiedlist; }); $window->show_all; Gtk2->main; sub make_sub_list { my $store = Gtk2::ListStore->new (qw(Glib::Int Glib::Int Glib::String)); # Note this nifty trick for filling the list... tie my @a, 'Gtk2::SimpleList::TiedList', $store; @a = @_; return \@a; }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

      Hello Zentara,

      Thanks for that example. I'm going to give you a vote as that snippet of code will come in handy on another project. However I'm in a terminal win32 enviroment,

Re: Perl Menus
by LanX (Saint) on Oct 01, 2014 at 01:09 UTC

      Hello Rolf,

      Curses::UI in a Win32 enviroment hangs on alot of the keystrokes...I had to modify some of the pm files in the curses::ui core folder just to get a few of the basic keystrokes to even work. I'm not going to do that for each function.

Re: Perl Menus
by Laurent_R (Canon) on Oct 01, 2014 at 06:19 UTC
    But are you already using some form of interface to view the file and be able to select a row?

      Hello Laurent_R,

      That is correct. There is a basic console menu program which asks for a user input such as: Car Make, Car Model...and based on that information it pulls up everything from that file. What needs to happen next is selecting that individual Make, Model and owner information and once selected another screen appears with fields to edit...such has car payment, change of personal information etc...while using the arrow keys or tab key.