Advertisement
Guest User

Untitled

a guest
Oct 10th, 2011
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. With dumping, no curses:
  2.  
  3. ================================================================
  4. our $i = 0;
  5. our $j = 0;
  6. our @marray= ();
  7. our $lhash = {};
  8.  
  9. foreach my $key ( keys %record) {
  10. foreach my $att ( keys %{ $record{$key} } ) {
  11. if ($att eq 'mail') {
  12. push(@marray, ${$record{$key}{$att}}[0]);
  13. }
  14. }
  15. }
  16.  
  17. foreach my $key ( keys %record) {
  18. foreach my $att ( keys %{ $record{$key} } ) {
  19. if ($att eq 'cn' ) {
  20. $lhash-> { $marray[$j] } = ${$record{$key}{$att}}[0];
  21. $j = $j + 1;
  22. }
  23. }
  24. }
  25.  
  26. print Dumper @marray;
  27. print Dumper @lhash;
  28. ================================================================
  29.  
  30. Output:
  31. $VAR1 = 'Gino.Francescutti@xxx.com';
  32. $VAR2 = 'Gino.Lisignoli@xxx.co.nz';
  33. $VAR1 = {
  34. 'Gino.Lisignoli@xxx.co.nz' => 'Gino Lisignoli',
  35. 'Gino.Francescutti@xxx.com' => 'Gino Francescutti'
  36. };
  37.  
  38. But, Code with Curses::UI Fails:
  39.  
  40. ================================================================
  41. our $i = 0;
  42. our $j = 0;
  43. our @marray= ();
  44. our $lhash = {};
  45.  
  46. foreach my $key ( keys %record) {
  47. foreach my $att ( keys %{ $record{$key} } ) {
  48. if ($att eq 'mail') {
  49. push(@marray, ${$record{$key}{$att}}[0]);
  50. }
  51. }
  52. }
  53.  
  54. foreach my $key ( keys %record) {
  55. foreach my $att ( keys %{ $record{$key} } ) {
  56. if ($att eq 'cn' ) {
  57. $lhash-> { $marray[$j] } = ${$record{$key}{$att}}[0];
  58. $j = $j + 1;
  59. }
  60. }
  61. }
  62.  
  63. #curses UI
  64. my $cui = new Curses::UI( -color_support => 1 );
  65. my @menu = (
  66. {
  67. -label => 'File',
  68. -submenu => [ { -label => 'Exit ^Q', -value => \&exit_dialog } ]
  69. },
  70. );
  71.  
  72. #Exit Dialog
  73. sub exit_dialog() {
  74. my $return = $cui->dialog(
  75. -message => "Do you really want to quit?",
  76. -title => "Are you sure???",
  77. -buttons => [ 'yes', 'no' ],
  78.  
  79. );
  80.  
  81. exit(0) if $return;
  82. }
  83.  
  84. #Add menu
  85. my $menu = $cui->add(
  86. 'menu', 'Menubar',
  87. -menu => \@menu,
  88.  
  89. -fg => "blue",
  90. );
  91.  
  92. #Add Window
  93. my $win1 = $cui->add(
  94. 'win1', 'Window',
  95. -border => 1,
  96. -y => 1,
  97. -bfg => 'red',
  98. );
  99.  
  100.  
  101. #Listbox, returns selected value
  102. my $listbox; $listbox = $win1->add(
  103. 'list',
  104. 'Listbox',
  105. -values => @marray,
  106. -lables => $lhash,
  107. -onchange => sub { exit($_[0]->get)}
  108. );
  109.  
  110. $cui->set_binding( sub { $menu->focus() }, "\cX" );
  111. $cui->set_binding( \&exit_dialog, "\cQ" );
  112. $listbox->focus();
  113. $cui->mainloop();
  114.  
  115.  
  116. ================================================================
  117.  
  118. Output:
  119.  
  120. Odd number of elements in hash assignment at /usr/share/perl5/Curses/UI/Container.pm line 72.
  121. 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.
  122.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement