• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:


Please help me with the passing the correct syntax to the
scrolling_list function in the CGI.pm
I am reading the following from the file:

123 ./test1 Test1 Directory
126 ./test2 Test2 Diredctory
435 ./test3 Test3 Directory

I have assigned the
@LIST1 aray  - the number values and
@LIST2 array - directory name
@LIST3 array - Directory discription

Now I want to create a scroll box with the name 'topic' where it will display the @LIST3 array as the Labels and @LIST1 as values.

The ultimate goal is to pass to the Web page the discription to be displayed in the form as a label and the encoded directory number as a value to each label.
I am using the following sub:
I have to create a hash using these 2 arrays inside the Function.
Please help me with this.

my(@list1) = @LIST1;
my(@list3) = @LIST3;

print scrolling_list(-name=> 'topic',
            -values=> ????? ,
            -label=?????  );

Thank You.
  • 3
1 Solution
here is a sample program that demonstrates how to create a multiple selection list box from the file format you have given above...

123 ./test1 Test1 Directory
126 ./test2 Test2 Diredctory
435 ./test3 Test3 Directory


## Open the data file and read all the lines
open(IN,"/tmp/in.txt") || die $!;

## For every line get the number, directory and the directory description
  ($one,$two,$three)=split(/ /,$_,3);
  ## Store the number as the key to the hash and the description
  ## as the value to the hash!!
@labels=keys %labels; ## Get all the keys of the hash

use CGI;
$query=new CGI;

print "Content-type: text/html\n\n";

print "<B>Here is the list box</B><BR>\n";

## Create a multiple select list box
## if you dont want multiple selection, male -multiple=>false

print "<FORM method=post action=$ENV{SCRIPT_NAME}>\n";
print $query->scrolling_list(-name=>'topic',

print "</FORM>\n";
sorry for the mistake..

the comment in the above program should be

## if you dont want multiple selection, make -multiple=>'',


## if you dont want multiple selection, make -multiple=>false,
sstoukAuthor Commented:
Thanks it worked, however the first element of the Hash is empty.
This creates 4 elements and the first one is empty value and empty key.

If you know how to get rid of the first element in the hash I would appriciate your answer. You earned Your points anyway.

Thank You very much!
Hmm! i checked the code again and i get 3 values.

the only reason i think you might be getting that empty value is due to the presence of an empty line in the input file.

i added a blank line in the input file (in.txt) & i got an extra, empty element in the list box!!

Hope that helps.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now