Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- With dumping, no curses:
- ================================================================
- our $i = 0;
- our $j = 0;
- our @marray= ();
- our $lhash = {};
- foreach my $key ( keys %record) {
- foreach my $att ( keys %{ $record{$key} } ) {
- if ($att eq 'mail') {
- push(@marray, ${$record{$key}{$att}}[0]);
- }
- }
- }
- foreach my $key ( keys %record) {
- foreach my $att ( keys %{ $record{$key} } ) {
- if ($att eq 'cn' ) {
- $lhash-> { $marray[$j] } = ${$record{$key}{$att}}[0];
- $j = $j + 1;
- }
- }
- }
- print Dumper @marray;
- print Dumper @lhash;
- ================================================================
- Output:
- $VAR1 = 'Gino.Francescutti@xxx.com';
- $VAR2 = 'Gino.Lisignoli@xxx.co.nz';
- $VAR1 = {
- 'Gino.Lisignoli@xxx.co.nz' => 'Gino Lisignoli',
- 'Gino.Francescutti@xxx.com' => 'Gino Francescutti'
- };
- But, Code with Curses::UI Fails:
- ================================================================
- our $i = 0;
- our $j = 0;
- our @marray= ();
- our $lhash = {};
- foreach my $key ( keys %record) {
- foreach my $att ( keys %{ $record{$key} } ) {
- if ($att eq 'mail') {
- push(@marray, ${$record{$key}{$att}}[0]);
- }
- }
- }
- foreach my $key ( keys %record) {
- foreach my $att ( keys %{ $record{$key} } ) {
- if ($att eq 'cn' ) {
- $lhash-> { $marray[$j] } = ${$record{$key}{$att}}[0];
- $j = $j + 1;
- }
- }
- }
- #curses UI
- my $cui = new Curses::UI( -color_support => 1 );
- my @menu = (
- {
- -label => 'File',
- -submenu => [ { -label => 'Exit ^Q', -value => \&exit_dialog } ]
- },
- );
- #Exit Dialog
- sub exit_dialog() {
- my $return = $cui->dialog(
- -message => "Do you really want to quit?",
- -title => "Are you sure???",
- -buttons => [ 'yes', 'no' ],
- );
- exit(0) if $return;
- }
- #Add menu
- my $menu = $cui->add(
- 'menu', 'Menubar',
- -menu => \@menu,
- -fg => "blue",
- );
- #Add Window
- my $win1 = $cui->add(
- 'win1', 'Window',
- -border => 1,
- -y => 1,
- -bfg => 'red',
- );
- #Listbox, returns selected value
- my $listbox; $listbox = $win1->add(
- 'list',
- 'Listbox',
- -values => @marray,
- -lables => $lhash,
- -onchange => sub { exit($_[0]->get)}
- );
- $cui->set_binding( sub { $menu->focus() }, "\cX" );
- $cui->set_binding( \&exit_dialog, "\cQ" );
- $listbox->focus();
- $cui->mainloop();
- ================================================================
- Output:
- Odd number of elements in hash assignment at /usr/share/perl5/Curses/UI/Container.pm line 72.
- Can't use string ("Gino.Francescutti@xx") as an ARRAY ref while "strict refs" in use at /usr/share/perl5/Curses/UI/Listbox.pm line 264.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement