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

Discussion in 'Perl Misc' started by prelim_questions@yahoo.com, Nov 24, 2007.

  1. Guest

    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!
     
    , Nov 24, 2007
    #1
    1. Advertising

  2. Ron Bergin Guest

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

    On Nov 23, 8:24 pm, 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.
     
    Ron Bergin, Nov 24, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott D Johnson
    Replies:
    1
    Views:
    1,132
    Scott D Johnson
    Sep 27, 2006
  2. volcano
    Replies:
    4
    Views:
    1,842
    volcano
    Sep 24, 2009
  3. kath
    Replies:
    4
    Views:
    814
    J. Gleixner
    Apr 9, 2007
  4. Dr. Leff
    Replies:
    3
    Views:
    330
    David Mark
    Oct 15, 2007
  5. Dr. Leff
    Replies:
    3
    Views:
    252
    David Mark
    Oct 15, 2007
Loading...

Share This Page