How to Add dynamic array/hashes to Curses::UI:Listbox -lables

How to Add dynamic array/hashes to Curses::UI:Listbox -lables

am 05.01.2008 07:40:45 von Sibu

Hai Perl Curses:UI users,

I am new to perl and i am trying to develop an textmode application in
perl using Curses::UI
I can add a Curses:UI:Listbox widget to my application and it works
fine.

I read data from a text file and stored in to an array
the i try to use this array in Listbox but i failed.
my problem is that how i manage the options ( -values, -labels ) in
Curses::UI:Listbox?
Should I use hashes or arrays?

Here is my code ie extracted from my original

#!/usr/bin/perl

#since am using unix machine

use strict;
use warnings;
use Curses::UI;

my $cui = new Curses::UI ( -clear_on_exit => 1, -color_support => 0);

my $win1 = $cui->add(
'win1', 'Window',
-title => 'HEAD',
-padtop => 1, # leave space for the menu
-border => 1,
-ipad => 0,
-bold => 1,
);

## READ DATA FROM FILE
my $kuricompfile="kuricomp.dat";
open(INP,$kuricompfile) || die "Cant open $kuricompfile" ;
my @companies=;
close(INP);

my $company;
my $counter=1;
my @myvalues;
my %myhash;

foreach $company (@companies)
{
$myhash{$counter}=chop($company);
$counter+=1;
}
@myvalues=keys %myhash;

my $comp_code = $win1->add(
'comp_code', 'Listbox',
-width => 8,
-y => 1, -x => 17,
-values => @myvalues,
-lables => %myhash,
);
cui->MainLoop;

----------- code over here -------


when i run this code, perl gives me the following error message:

Can't use string ("4") as an ARRAY ref while "strict refs" in use at /
usr/local/lib/perl5/site_perl/5.8.6/Curses/UI/Listbox.pm line 264.

The data file kuricomp.dat contains the following data

1001 COMP.HEAD NEW.ADDRESS
1235 ANOTHER.COMP PLACE
1002 HELLO.IMP ADD1
1256 2563 256


Kindly help me to correct the problem

Thanks in advance,

Sibu.N.L

Re: How to Add dynamic array/hashes to Curses::UI:Listbox -lables

am 07.01.2008 05:39:32 von Sibu

On Jan 5, 11:40 am, Sibu wrote:
> Hai Perl Curses:UI users,
>
> I am new to perl and i am trying to develop an textmode application in
> perl using Curses::UI
> I can add a Curses:UI:Listbox widget to my application and it works
> fine.
>
> I read data from a text file and stored in to an array
> the i try to use this array in Listbox but i failed.
> my problem is that how i manage the options ( -values, -labels ) in
> Curses::UI:Listbox?
> Should I use hashes or arrays?
>
> Here is my code ie extracted from my original
>
> #!/usr/bin/perl
>
> #since am using unix machine
>
> use strict;
> use warnings;
> use Curses::UI;
>
> my $cui = new Curses::UI ( -clear_on_exit => 1, -color_support => 0);
>
> my $win1 = $cui->add(
> 'win1', 'Window',
> -title => 'HEAD',
> -padtop => 1, # leave space for the menu
> -border => 1,
> -ipad => 0,
> -bold => 1,
> );
>
> ## READ DATA FROM FILE
> my $kuricompfile="kuricomp.dat";
> open(INP,$kuricompfile) || die "Cant open $kuricompfile" ;
> my @companies=;
> close(INP);
>
> my $company;
> my $counter=1;
> my @myvalues;
> my %myhash;
>
> foreach $company (@companies)
> {
> $myhash{$counter}=chop($company);
> $counter+=1;}
>
> @myvalues=keys %myhash;
>
> my $comp_code = $win1->add(
> 'comp_code', 'Listbox',
> -width => 8,
> -y => 1, -x => 17,
> -values => @myvalues,
> -lables => %myhash,
> );
> cui->MainLoop;
>
> ----------- code over here -------
>
> when i run this code, perl gives me the following error message:
>
> Can't use string ("4") as an ARRAY ref while "strict refs" in use at /
> usr/local/lib/perl5/site_perl/5.8.6/Curses/UI/Listbox.pm line 264.
>
> The data file kuricomp.dat contains the following data
>
> 1001 COMP.HEAD NEW.ADDRESS
> 1235 ANOTHER.COMP PLACE
> 1002 HELLO.IMP ADD1
> 1256 2563 256
>
> Kindly help me to correct the problem
>
> Thanks in advance,
>
> Sibu.N.L

I got the answer from comp.lang.perl.misc (muami) and this problem is
solved.

by changing these lines

-values => @myvalues,
-lables => %myhash,

to
-values => \@myvalues,
-labels => \%myhash,

Thank you muami,

Sibu.N.L