Using arrays in Curses::UI:Listbox

Using arrays in Curses::UI:Listbox

am 04.01.2008 08:12:08 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: Using arrays in Curses::UI:Listbox

am 05.01.2008 06:07:47 von paduille.4061.mumia.w+nospam

On 01/04/2008 01:12 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?
>
> [...]
> my $comp_code = $win1->add(
> 'comp_code', 'Listbox',
> -width => 8,
> -y => 1, -x => 17,
> -values => \@myvalues,
> -lables => \%myhash,
> );
> cui->MainLoop;
>

Note the changes I made above—you only needed backslashes before the
array and the hash.

Re: Using arrays in Curses::UI:Listbox

am 05.01.2008 07:47:17 von Sibu

On Jan 5, 10:07 am, "Mumia W." +nos...@earthlink.net> wrote:
> On 01/04/2008 01:12 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?
>
> > [...]
> > my $comp_code = $win1->add(
> > 'comp_code', 'Listbox',
> > -width => 8,
> > -y => 1, -x => 17,
> > -values => \@myvalues,
> > -lables => \%myhash,
> > );
> > cui->MainLoop;
>
> Note the changes I made above--you only needed backslashes before the
> array and the hash.

Hai Mumia,

Its solved!

Thank you,

Sibu.N.L