How to generate radio buttons in Perl/CGI script with call to shellscript?

P

prelim_questions

My background: I am very new to Perl, CGI, and HTML. UNIX is okay.

I want to generate many (say 50+) radio_groups, each occurring on a
different webpage (like a quiz). The most convenient way for me to do
this is for each radio group to reference a particular file in my
directory which contains the appropriate question and possible answers
(different file for each radio group).

So for example:

Instead of hand typing each radio group like this:

print "<p><em>How far can they fly?</em><br>",
radio_group(
-name=>'how far',
-values=>['10 ft','1 mile','10 miles','real
far'],
-default=>'1 mile'); # (example from
perldoc)


I want to automatically generate this form with something like:

print "<p><em> $question </em><br>",
radio_group(
-name=>$id,
-values=>[$value1,$value2,$value3,$value4],
-default=>$value1);

where $question=` cat /home/username/file1 | head -1` { or however
you say the first line of a file in Perl}

and [$value1,$value2,$value3,$value4] = {the remaining 4 lines in /
home/username/file1}.


Now to make it slightly more complicated, each file is generated by a
shell script which I would prefer to reference directly in my Perl
script. In case that is not clear, say I use ./home/username/
radio_script -option1 to generate file1
../home/username/radio_script -option2 to generate file2
etc.

I have tried many variations on the system command to do this without
success. How do I do this?

Undoubtedly, I have may have been unclear at times. Please ask, and I
can clarify.

Thanks!
 
R

Ron Bergin

My background: I am very new to Perl, CGI, and HTML. UNIX is okay.

I want to generate many (say 50+) radio_groups, each occurring on a
different webpage (like a quiz). The most convenient way for me to do
this is for each radio group to reference a particular file in my
directory which contains the appropriate question and possible answers
(different file for each radio group).

So for example:

Instead of hand typing each radio group like this:

print "<p><em>How far can they fly?</em><br>",
radio_group(
-name=>'how far',
-values=>['10 ft','1 mile','10 miles','real
far'],
-default=>'1 mile'); # (example from
perldoc)

I want to automatically generate this form with something like:

print "<p><em> $question </em><br>",
radio_group(
-name=>$id,
-values=>[$value1,$value2,$value3,$value4],
-default=>$value1);

where $question=` cat /home/username/file1 | head -1` { or however
you say the first line of a file in Perl}

and [$value1,$value2,$value3,$value4] = {the remaining 4 lines in /
home/username/file1}.
open my $file1 '<', '/home/username/file1' or die "file1 open failed
$!";
chomp(my @file1 = <$file1>);
close $file1;

my $question = shift @file1;
print "<p><em> $question </em><br>",
radio_group(
-name=>$id,
-values=>\@file1,
-default=>$file1[0]
);
Now to make it slightly more complicated, each file is generated by a
shell script which I would prefer to reference directly in my Perl
script. In case that is not clear, say I use ./home/username/
radio_script -option1 to generate file1
./home/username/radio_script -option2 to generate file2
etc.

I have tried many variations on the system command to do this without
success. How do I do this?
for my $num (1..50) {
system("/home/username/radio_script -option$num");
}
Undoubtedly, I have may have been unclear at times. Please ask, and I
can clarify.

Thanks!

Personally, I'd drop the indirection of using the cat command and
shell script, and instead do everything in Perl without creating the
50+ question files.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top