Solved

Hash

Posted on 2000-04-13
4
274 Views
Last Modified: 2012-06-21
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.

sub CREATE_LIST_FORM
{
my(@list1) = @LIST1;
my(@list3) = @LIST3;

print scrolling_list(-name=> 'topic',
            -values=> ????? ,
            -size=>12,
            -multiple=>'',
            -label=?????  );
};

Thank You.
0
Comment
Question by:sstouk
  • 3
4 Comments
 
LVL 16

Accepted Solution

by:
maneshr earned 100 total points
ID: 2712869
here is a sample program that demonstrates how to create a multiple selection list box from the file format you have given above...

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

=========list.pl
#!/usr/local/bin/perl

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

## For every line get the number, directory and the directory description
foreach(@lines){
  ($one,$two,$three)=split(/ /,$_,3);
  ## Store the number as the key to the hash and the description
  ## as the value to the hash!!
  $labels{$one}=$three;
  push(@LIST2,$two);
}
@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',
-values=>\@labels,
-size=>3,
-multiple=>true,
-labels=>\%labels);

print "</FORM>\n";
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2712879
sorry for the mistake..

the comment in the above program should be

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

NOT

## if you dont want multiple selection, make -multiple=>false,
0
 
LVL 6

Author Comment

by:sstouk
ID: 2713216
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!
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2713260
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.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question