Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: trying to populate curses menus from text files

by kcott (Chancellor)
on Nov 01, 2013 at 04:29 UTC ( #1060705=note: print w/replies, xml ) Need Help??

in reply to trying to populate curses menus from text files

G'day boscaiolo,

Welcome to the monastery.

Unfortunately, as already pointed out, your post is lacking various pieces of information that would help us to help you. In addition to a lack of details about the input data, there's no concrete indication of your expected output or what, if anything, you've already tried and perhaps had difficulties with. Furthermore, you've provided no links to information you've made reference to: I could probably work out where Curses::UI is documented but I shouldn't have to; I've got absolutely no idea what "tutorial" you're referring to — please read "What shortcuts can I use for linking to other information?".

From the information you have provided, I suspect your code would look something like this:

my @list_of_files = qw{File Edit Help}; my $regex_to_match_label = qr{LABEL="([^"]+)}; my @menu; for my $filename (@list_of_files) { open my $fh, '<', $filename or die "Can't read $filename: $!"; my @submenu; push @menu, { -label => $filename, -submenu => \@submenu }; while (<$fh>) { if (/$regex_to_match_label/) { my $label = $1; push @submenu, { -label => $label, -value => sub { generic_dialog($la +bel) } }; } } close $fh; }

-- Ken

Replies are listed 'Best First'.
Re^2: trying to populate curses menus from text files
by boscaiolo (Initiate) on Nov 02, 2013 at 12:19 UTC

    Thanks for your reply. You divined my intention exactly in spite of my rather minimal information! In fact, I do not need the regex match since the text file comprises one item per line (as I omitted to explain), so my $label = $_; is all I need.

    Your suggested is lucid and perfect to my needs. I don't know why I find hash and array operations so confusing.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1060705]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2018-08-15 11:25 GMT
Find Nodes?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:

    Results (160 votes). Check out past polls.