Labelling Radio Group Values

I have sucessfully created as Radio-group along the lines of

[at] TiesArray = SSDArray($uniqueorgref);
if ( [at] TiesArray[0] ne "") {

[at] TiesDesc = SSDDescArray($uniqueorgref);
%TiesHash = [at] TiesDesc;
$q = new CGI;
print $q->start_form(-method=>"POST",
-action=>"http://....../cgi-bin/ViewQuote.pl"),
$q->p("The system has identified .... etc and click the SEND
button."),
$q->hidden("uniqueorgref", $uniqueorgref),
$q->radio_group(-name=>"hideordNo", -values=>\ [at] TiesArray, -
linebreak=>"true", -labels=>\%TiesHash),
$q->submit("Send"),
$q->hr,
$q->end_form;
}


My problem is that the hash that describes the radio group values -
%TiesHash - (and should replace them on screen) is not operating. Any
thoughts?



--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Stephen Allen [ Di, 11 Januar 2011 16:44 ] [ ID #2053004 ]

Re: Labelling Radio Group Values

Hi Stephen,

a few comments on your code:

On Tuesday 11 Jan 2011 17:44:32 Stephen Allen wrote:
> I have sucessfully created as Radio-group along the lines of
>
> [at] TiesArray = SSDArray($uniqueorgref);

Add:

{{{
use strict;
use warnings;
}}}

to the start of your script. Then declare all variables using "my":

http://perl-begin.org/tutorials/bad-elements/#no-strict-and- warnings

> if ( [at] TiesArray[0] ne "") {
>
> [at] TiesDesc = SSDDescArray($uniqueorgref);

You should indent properly. See:

http://perl-begin.org/tutorials/bad-elements/#no-indentation


> %TiesHash = [at] TiesDesc;

Are you sure you want to initialise a hash from an array this way?

> $q = new CGI;

Avoid indirect object notation:

http://perl-begin.org/tutorials/bad-elements/#indirect-objec t-notation

And you should call the CGI object with a more meaningful name than "$q".

> print $q->start_form(-method=>"POST",
> -action=>"http://....../cgi-bin/ViewQuote.pl"),
> $q->p("The system has identified .... etc and click the SEND
> button."),
> $q->hidden("uniqueorgref", $uniqueorgref),
> $q->radio_group(-name=>"hideordNo", -values=>\ [at] TiesArray, -
> linebreak=>"true", -labels=>\%TiesHash),
> $q->submit("Send"),
> $q->hr,
> $q->end_form;

I don't like CGI.pm's HTML generation methods too much (they are bloat if you
ask me). A templating system such as the Template Toolkit will be better:

http://perl-begin.org/uses/text-generation/

> }
>
>
> My problem is that the hash that describes the radio group values -
> %TiesHash - (and should replace them on screen) is not operating. Any
> thoughts?

You can try using a debugger to see where it goes wrong:

http://perl-begin.org/topics/debugging/

Regards,

Shlomi Fish

--
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
My Public Domain Photos - http://www.flickr.com/photos/shlomif/

Chuck Norris can make the statement "This statement is false" a true one.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Shlomi Fish [ Mi, 12 Januar 2011 10:44 ] [ ID #2053006 ]

Re: Labelling Radio Group Values

Stephen Allen wrote:
> I have sucessfully created as Radio-group along the lines of
>
> [at] TiesArray = SSDArray($uniqueorgref);
> if ( [at] TiesArray[0] ne "") {

You are testing a list against a scalar value, but fortunately your list
has only one element. If you had warnings enabled then perl would have
told you to use a scalar instead of a list:

if ( $TiesArray[ 0 ] ne "" ) {

And why are you comparing $TiesArray[ 0 ] to an empty string? Will
$TiesArray[ 0 ] always contain a valid string? Or are you trying to
determine if [at] TiesArray has any elements at all?



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
jwkrahn [ Mi, 12 Januar 2011 11:16 ] [ ID #2053007 ]

Re: Labelling Radio Group Values

Hi Shlomi

Thanks for your comments.

In fact, the problem was enirely my own fault and did not exihibit in
the code I published.

More specifically the hash I created in %TiesHash did not use the
correct Key - hence it didn't work.

Get that right and the rest falls into place nicely.

Stephen




On Jan 12, 9:44=A0am, shlo... [at] iglu.org.il (Shlomi Fish) wrote:
> Hi Stephen,
>
> a few comments on your code:
>
> On Tuesday 11 Jan 2011 17:44:32 Stephen Allen wrote:
>
> > I have sucessfully created as Radio-group along the lines of
>
> > [at] TiesArray =3D SSDArray($uniqueorgref);
>
> Add:
>
> {{{
> use strict;
> use warnings;
>
> }}}
>
> to the start of your script. Then declare all variables using "my":
>
> http://perl-begin.org/tutorials/bad-elements/#no-strict-and- warnings
>
> > if ( [at] TiesArray[0] ne "") {
>
> > [at] TiesDesc =3D SSDDescArray($uniqueorgref);
>
> You should indent properly. See:
>
> http://perl-begin.org/tutorials/bad-elements/#no-indentation
>
> > %TiesHash =3D [at] TiesDesc;
>
> Are you sure you want to initialise a hash from an array this way?
>
> > $q =3D new CGI;
>
> Avoid indirect object notation:
>
> http://perl-begin.org/tutorials/bad-elements/#indirect-objec t-notation
>
> And you should call the CGI object with a more meaningful name =A0than "$=
q".
>
> > print =A0 =A0 =A0$q->start_form(-method=3D>"POST",
> > -action=3D>"http://....../cgi-bin/ViewQuote.pl"),
> > $q->p("The system has identified .... etc and click the SEND
> > button."),
> > $q->hidden("uniqueorgref", $uniqueorgref),
> > $q->radio_group(-name=3D>"hideordNo", -values=3D>\ [at] TiesArray, -
> > linebreak=3D>"true", -labels=3D>\%TiesHash),
> > $q->submit("Send"),
> > $q->hr,
> > $q->end_form;
>
> I don't like CGI.pm's HTML generation methods too much (they are bloat if=
you =A0
> ask me). A templating system such as the Template Toolkit will be better:
>
> http://perl-begin.org/uses/text-generation/
>
> > }
>
> > My problem is that the hash that describes the radio group values -
> > %TiesHash - (and should replace them on screen) is not operating. Any
> > thoughts?
>
> You can try using a debugger to see where it goes wrong:
>
> http://perl-begin.org/topics/debugging/
>
> Regards,
>
> =A0 =A0 =A0 =A0 Shlomi Fish
>
> --
> ------------------------------------------------------------ -----
> Shlomi Fish =A0 =A0 =A0http://www.shlomifish.org/
> My Public Domain Photos -http://www.flickr.com/photos/shlomif/
>
> Chuck Norris can make the statement "This statement is false" a true one.
>
> Please reply to list if it's a mailing list post -http://shlom.in/reply.


--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Stephen Allen [ Mi, 12 Januar 2011 11:08 ] [ ID #2053015 ]

Re: Labelling Radio Group Values

On 2011-01-12 10:44, Shlomi Fish wrote:

> Add:
>
> {{{
> use strict;
> use warnings;
> }}}
>
> to the start of your script.

That adds 3 ENTERs and LEAVEs for no good reason. The code is not in a
tight loop, so that doesn't matter much, but there is more:

perl -MData::Dumper -wle '
$x = 1;
{{{
use strict;
use warnings;
$y = 1;
}}}
$z = 1;
'
Global symbol "$y" requires explicit package name at -e line 6.
Execution of -e aborted due to compilation errors.

So both the $x and $z are missed, if you would adopt the silly {{{ ...
}}} notation.

--
Ruud

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
rvtol+usenet [ Mi, 12 Januar 2011 11:31 ] [ ID #2053016 ]

Re: Labelling Radio Group Values

>>>>> "R" == Ruud <rvtol+usenet [at] isolution.nl> writes:

R> On 2011-01-12 10:44, Shlomi Fish wrote:
>> Add:
>>
>> {{{
>> use strict;
>> use warnings;
>> }}}
>>
>> to the start of your script.

R> That adds 3 ENTERs and LEAVEs for no good reason. The code is not in a
R> tight loop, so that doesn't matter much, but there is more:

R> perl -MData::Dumper -wle '
R> $x = 1;
R> {{{
R> use strict;
R> use warnings;
R> $y = 1;
R> }}}
R> $z = 1;
R> '
R> Global symbol "$y" requires explicit package name at -e line 6.
R> Execution of -e aborted due to compilation errors.

R> So both the $x and $z are missed, if you would adopt the silly {{{
R> ... }}} notation.

shlomi does that stupid {{{}}} thing to marks his code changes in
posts. does that too on the beginner's list. very moronic style.

uri

--
Uri Guttman ------ uri [at] stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Uri Guttman [ Mi, 12 Januar 2011 22:36 ] [ ID #2053021 ]
Perl » gmane.comp.lang.perl.beginners » Labelling Radio Group Values

Vorheriges Thema: Return value from function
Nächstes Thema: calculate average