Click here to get back home

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

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
How to Add dynamic array/hashes to Curses::UI:Listbox -lables Sibu 01-05-2008
Posted by Sibu on January 5, 2008, 1:40 am
Please log in for more thread options
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=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

Posted by Sibu on January 6, 2008, 11:39 pm
Please log in for more thread options
> 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=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

Similar ThreadsPosted
Accessing listbox using perl? May 16, 2007, 7:48 pm
Reading listbox/combobox/textbox using perl? May 16, 2007, 6:01 pm
Win32::GUI newbie question re dynamic GUI building October 6, 2005, 8:44 pm
mod_perl-1.99_16 won't make: don't know how to make dynamic September 1, 2004, 10:52 pm
CDK vs Curses::UI April 15, 2005, 11:12 am
Perl MakeMaker - how to force Perl linking with the static C library (libcrt.lib) instead of dynamic C library (msvcrt.lib) April 17, 2007, 5:22 pm
keylist for set_binding in Curses::UI February 7, 2005, 3:11 pm
Curses-perl that doesn't live up to it's name? November 10, 2006, 10:30 pm
Installing Curses Module? February 22, 2008, 11:45 am
Curses::Widgets::Menu Question May 11, 2005, 8:32 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap