Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to generate radio buttons in Perl/CGI script with call to shellscript?

Reply
Thread Tools

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

 
 
prelim_questions@yahoo.com
Guest
Posts: n/a
 
      11-24-2007
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!




 
Reply With Quote
 
 
 
 
Ron Bergin
Guest
Posts: n/a
 
      11-24-2007
On Nov 23, 8:24 pm, (E-Mail Removed) 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 "<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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Radio buttons in PDF script Paul E. Schoen Javascript 0 07-30-2009 03:04 AM
Created Radio Buttons displaying as if they were conventional buttons Dr. Leff Javascript 3 10-15-2007 09:47 PM
Created Radio Buttons displaying as if they were conventional buttons Dr. Leff Javascript 3 10-15-2007 05:18 AM
ASP.NET Reset Radio Button in a group of Radio Buttons Scott D Johnson ASP .Net 1 09-27-2006 10:38 PM



Advertisments