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

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

am 24.11.2007 05:24:23 von 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 "

How far can they fly?
",
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 "

$question
",
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!

Re: How to generate radio buttons in Perl/CGI script with call to

am 24.11.2007 06:05:39 von Ron Bergin

On Nov 23, 8:24 pm, prelim_questi...@yahoo.com wrote:
> 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 "

How far can they fly?
",
> 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 "

$question
",
> 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 "

$question
",
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.