Using dialog(1) this snippet allow users to use a GUI to configure options.
#!/usr/bin/perl use IPC::Open3; use File::Temp qw/ :mktemp /; my $options={ 'height'=>30, 'menuheight'=>20, 'width'=>50, 'title'=>"My dialog", }; my $val={ 'Options1'=>30, 'String_Options'=>30, 'Another_Options'=>30, 'Another_again'=>"My dialog", }; perlog_run($options,$val); sub create_cmd_line() { my ($hropt,$hrentry)=@_; my $cmdline="dialog --nocancel --inputmenu \"$hropt->{'title'}\" $ +hropt->{'height'} $hropt->{'width'} $hropt->{'menuheight'}"; foreach(sort keys %$hrentry) { $cmdline .= " \"$_\" \"$hrentry->{$_}\""; } return $cmdline; } sub perlog_run() { my ($hropt,$hrentry)=@_; my $d; for(;;) { open OLDERR, ">&", \*STDERR; close(STDERR); (*STDERR,$filename)=mkstemp("perllogXXXXXX"); my $c=&create_cmd_line($hropt,$hrentry); system("$c"); close (STDERR); open STDERR, ">&", \*OLDERR; close (OLDERR); open IN,"<$filename"; $_=<IN>; close(IN); unlink $filename; (/[^\s]+\s([^\s]+)\s(.+)$/)?$hrentry->{$1}=$2:last; } }
New version (FULL ini format supported!)
use Getopt::Long; my $val={'height'=>30,'menuheight'=>20,'width'=>50,'title'=>"My dialog +",}; my $path="config/ini/"; my $file,$help; my %iniopts=('case'=>'sensitive'); GetOptions ("conf=s"=> \$file, "path=s"=> \$path); if($file eq "") { print RESET "**************"; print GREEN "PER"; print RESET "[L][DIA]"; print GREEN "LOG by Luca Benini - 2004 - GPL"; print RESET "**************\nUsage:\n\t"; print BLUE "$0 [--path=/path/to/ini/file] [--conf=inifile]\n" +; print RESET "Default path:\n\t"; print BLUE "$path"; print RESET "\n"; exit(0); } $val->{'title'}="$file | Luca Benini Configure"; my $Config = ReadINI("$path$file",%iniopts) or die "[READ] Unable to o +pen $path$ file: $!"; foreach(keys %$Config) { my $t=$Config->{$_}; foreach(keys %$t) { delete $t->{$_} if (/#/); } } my $i=perlog_config($val,$Config); WriteINI("$path$file",$Config) or die "[WRITE] Unable to open $path$fi +le: $!"; sub perlog_config() { my ($hropt,$hrentry)=@_; while(1) { my $i=perlog_run_select($hropt,$hrentry); return if ($i eq ""); perlog_run_rename($hropt,$hrentry->{$i}); } } sub create_cmd_line_menu() { my ($hropt,$hrentry)=@_; my $cmdline="dialog --nocancel --menu \"$hropt->{'title'}\" $h +ropt->{'he ight'} $hropt->{'width'} $hropt->{'menuheight'}"; foreach(sort keys %$hrentry) { $cmdline .= " \"$_\" \"$_\""; } return $cmdline; } sub create_cmd_line_imenu() { my ($hropt,$hrentry)=@_; my $cmdline="dialog --nocancel --inputmenu \"$hropt->{'title'} +\" $hropt- >{'height'} $hropt->{'width'} $hropt->{'menuheight'}"; foreach(sort keys %$hrentry) { $cmdline .= " \"$_\" \"$hrentry->{$_}\""; } return $cmdline; } sub perlog_run_select() { my ($hropt,$hrentry)=@_; my $d; open OLDERR, ">&", \*STDERR; close(STDERR); (*STDERR,$filename)=mkstemp("perllogXXXXXX"); my $c=&create_cmd_line_menu($hropt,$hrentry); system("$c"); close (STDERR); open STDERR, ">&", \*OLDERR; close (OLDERR); open IN,"<$filename"; $_=<IN>; close(IN); unlink $filename or die ; return $_; } sub perlog_run_rename() { my ($hropt,$hrentry)=@_; my $d; for(;;) { open OLDERR, ">&", \*STDERR; close(STDERR); (*STDERR,$filename)=mkstemp("perllogXXXXXX"); my $c=&create_cmd_line_imenu($hropt,$hrentry); system("$c"); close (STDERR); open STDERR, ">&", \*OLDERR; close (OLDERR); open IN,"<$filename"; $_=<IN>; close(IN); unlink $filename or die ; (/[^\s]+\s(.+)\s([^\s]+)$/)?$hrentry->{$1}=$2:last; } }

In reply to Simple Hash gui (useful!) by Luca Benini

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.