Article View: best.schaft
Article #2Re: !! Perl Question - Selection Sets and Dynamic Text
From: Robert Coie
Date: Sat, 09 Dec 1995 00:00
Date: Sat, 09 Dec 1995 00:00
58 lines
2541 bytes
2541 bytes
Posted and mailed.
In article <gwalsh-0712951107450001@gwalsh.vip.best.com>, gwalsh@artec.com
(Greg Walsh) wrote:
: Any help on this would be appreciated.
:
: # da problem: ####
:
: I'm processing form data. At one point in the form, I use 4 different
: check boxes, each signifying a different subject the viewer is intrested
: in.
:
: I'm looking for the best method to arrange a dynamic paragraph built on
: responses. This would be pretty easy if I would use a <SELECT MULTIPLE>
: instead of four independent checkboxes; but each subject/selection has a
: pretty extensive discription attached, and I want more control over the
: layout. And.... I want natural sounding english.
[snip]
: (2) Option #B. Take the data in the four variables, put it into a comma
: (and space) delmited string that terminates in a period. Then (if two or
: more items were selected) change the last comma to the word "and". Of
: course, any set variable that doesnt contain data shouldn't print.
:
: # A model sentence using option #B ####
:
: You are interested in: $data{'BBB'}, $data{'CCC'} and $data{'DDD'}.
Would something like the following be useful?
$data{'AAA'} = "fishing";
$data{'BBB'} = "skiing";
$data{'CCC'} = "movies";
$data{'DDD'} = "programming";
@matches = ();
foreach( sort keys %data )
{
push( @matches, $data{$_} ) if $data{$_};
}
if( @matches )
{
$rsp = "You are interested in $matches[$[]";
for( $i = $[+1; $i <= $#matches - 1; $i++ )
{
$rsp .= ", $matches[$i]";
}
$rsp .= " and $matches[$#matches]" if $#matches > $[;
$rsp .= ".\n";
}
else
{
$rsp = "You have no interests at all.\n";
}
print $rsp;
Robert Coie
Implementor, Intrigue Corporation
rac@intrigue.com
Technical Details
Message-ID:
<rac-0912951222580001@intrigue.intrigue.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<gwalsh-0712951107450001@gwalsh.vip.best.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 161bbf,d9a1726cf20f68be,start X-Google-Attributes: gid161bbf,public X-Google-Thread: 11488e,d9a1726cf20f68be,start X-Google-Attributes: gid11488e,public X-Google-Thread: fa0ae,d9a1726cf20f68be,start X-Google-Attributes: gidfa0ae,public X-Google-Thread: fd796,d9a1726cf20f68be,start X-Google-Attributes: gidfd796,public From: rac@intrigue.com (Robert Coie) Subject: Re: !! Perl Question - Selection Sets and Dynamic Text Date: 1995/12/09 Message-ID: <rac-0912951222580001@intrigue.intrigue.com> X-Deja-AN: 121459898 references: <gwalsh-0712951107450001@gwalsh.vip.best.com> organization: Intrigue Corporation newsgroups: best.schaft,best.www,comp.infosystems.www.authoring.cgi,comp.lang.perl.misc