Using arrays in Curses::UI:Listbox

S

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=<INP>;
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
 
M

Mumia W.

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.
 
S

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?
[...]
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top