[29835] in Perl-Users-Digest
Perl-Users Digest, Issue: 1078 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 29 03:09:40 2007
Date: Thu, 29 Nov 2007 00:09:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 29 Nov 2007 Volume: 11 Number: 1078
Today's topics:
equivalent controls <wade@zaxfuuq.net>
Re: equivalent controls <jurgenex@hotmail.com>
Re: equivalent controls <wade@zaxfuuq.net>
Re: equivalent controls <jurgenex@hotmail.com>
Re: equivalent controls <wade@zaxfuuq.net>
How to persist and query a hash lookup in memory with P <jack_posemsky@yahoo.com>
Re: How to persist and query a hash lookup in memory wi <noreply@gunnar.cc>
Re: How to persist and query a hash lookup in memory wi jackposemsky@yahoo.com
Re: How to persist and query a hash lookup in memory wi <1usa@llenroc.ude.invalid>
Re: making the keys of a hash from parameters collected <rallabs@adelphia.net>
making the keys of a hash from parameters collected fro <rallabs@adelphia.net>
Re: making the keys of a hash from parameters collected <1usa@llenroc.ude.invalid>
new CPAN modules on Thu Nov 29 2007 (Randal Schwartz)
Re: page 124 of the camel book <uri@stemsystems.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 28 Nov 2007 19:25:13 -0700
From: "Wade Ward" <wade@zaxfuuq.net>
Subject: equivalent controls
Message-Id: <1196302638_185@sp12lax.superfeed.net>
use strict;
use warnings;
my $x_calc = 5.3;
my $x_sought = 7.321928094887362;
my $base = .5;
my $term = -.00057;
my $penultimate = -.00057;
my $cows_come_home = 0;
my $power = 1;
#$term = (10.0*(2.0**$x_calc) > 1600.0);
$term = 10.0*(2.0**$x_sought);
print STDOUT " is $term \n";
do {{
$x_calc++;
$power++;
last if $x_calc > 10;
print STDOUT "x calc is $x_calc\n";
print STDOUT "x_calc out is $x_calc\n";
print STDOUT "power out is $power\n";
do {{
$power++;
$x_calc++;
print STDOUT "power in is $power\n";
print STDOUT "x_calc in is $x_calc\n";
$x_sought = $x_sought - 1;
last if 1 > 0;
print STDOUT "x sought is $x_sought\n";
}} until $x_calc > 7.5;
$x_calc = $penultimate;
}} until ($power > 6);
print STDOUT "power is $power\n";
print STDOUT "base is $base\n";
# output prelims
is 1600
x calc is 6.3
x_calc out is 6.3
power out is 2
power in is 3
x_calc in is 7.3
power in is 4
x_calc in is 8.3
x calc is 0.99943
x_calc out is 0.99943
power out is 5
power in is 6
x_calc in is 1.99943
power in is 7
x_calc in is 2.99943
power in is 8
x_calc in is 3.99943
power in is 9
x_calc in is 4.99943
power in is 10
x_calc in is 5.99943
power in is 11
x_calc in is 6.99943
power in is 12
x_calc in is 7.99943
power is 12
base is 0.5
# end output prelims begin comment
I've got this nested do control to show the behavior I'm looking for.
Is there a slicker way to do this in perl than using the double curly
braces?
--
wade ward
wade@zaxfuuq.net
435 -838-7760
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
------------------------------
Date: Thu, 29 Nov 2007 03:52:37 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: equivalent controls
Message-Id: <9Iq3j.17146$r81.5080@trndny05>
Wade Ward wrote:
[...]
> do {{
> $x_calc++;
> $power++;
>
> last if $x_calc > 10;
> print STDOUT "x calc is $x_calc\n";
> print STDOUT "x_calc out is $x_calc\n";
> print STDOUT "power out is $power\n";
> do {{
> $power++;
> $x_calc++;
> print STDOUT "power in is $power\n";
> print STDOUT "x_calc in is $x_calc\n";
> $x_sought = $x_sought - 1;
> last if 1 > 0;
> print STDOUT "x sought is $x_sought\n";
>
> }} until $x_calc > 7.5;
> $x_calc = $penultimate;
> }} until ($power > 6);
[...]
> Is there a slicker way to do this in perl than using the double curly
> braces?
Absolutely, here it goes for your main loop:
while ($power < 6 and $x_calc < 10) {
$x_calc++;
$power++;
print "x calc is $x_calc\n";
print "x_calc out is $x_calc\n";
print "power out is $power\n";
while ($x_calc <= 7.5 ){
$power++;
$x_calc++;
print "power in is $power\n";
print "x_calc in is $x_calc\n";
}
$x_calc = $penultimate;
};
It also reduced the number of lines from 20 to 14 and IMHO is much more
readable, too.
jue
------------------------------
Date: Wed, 28 Nov 2007 21:21:41 -0700
From: "Wade Ward" <wade@zaxfuuq.net>
Subject: Re: equivalent controls
Message-Id: <1196309630_515@sp12lax.superfeed.net>
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:9Iq3j.17146$r81.5080@trndny05...
> Wade Ward wrote:
> [...]
>> do {{
>> $x_calc++;
>> $power++;
>>
>> last if $x_calc > 10;
>> print STDOUT "x calc is $x_calc\n";
>> print STDOUT "x_calc out is $x_calc\n";
>> print STDOUT "power out is $power\n";
>> do {{
>> $power++;
>> $x_calc++;
>> print STDOUT "power in is $power\n";
>> print STDOUT "x_calc in is $x_calc\n";
>> $x_sought = $x_sought - 1;
>> last if 1 > 0;
>> print STDOUT "x sought is $x_sought\n";
>>
>> }} until $x_calc > 7.5;
>> $x_calc = $penultimate;
>> }} until ($power > 6);
> [...]
>> Is there a slicker way to do this in perl than using the double curly
>> braces?
>
> Absolutely, here it goes for your main loop:
>
> while ($power < 6 and $x_calc < 10) {
> $x_calc++;
> $power++;
> print "x calc is $x_calc\n";
> print "x_calc out is $x_calc\n";
> print "power out is $power\n";
> while ($x_calc <= 7.5 ){
> $power++;
> $x_calc++;
> print "power in is $power\n";
> print "x_calc in is $x_calc\n";
> }
> $x_calc = $penultimate;
> };
>
> It also reduced the number of lines from 20 to 14 and IMHO is much more
> readable, too.
It sure looks like I'm torturing the syntax, but I got contract68 to work:
## contract68.pl
## one sided increasingly good guesses
## contributors: joe smith, jean luc, Jürgen Exner
use strict;
use warnings;
my $x_calc = 5.3;
my $x_sought = 7.321928094887362;
my $base = .5;
my $term = -.00057;
my $penultimate = -.00057;
my $cows_come_home = 0;
my $power = 1;
do {{
$term = $base**$power;
print STDOUT "term is $term \n";
print STDOUT "current is $penultimate \n";
$power++;
do {{
$penultimate = $x_calc;
$x_calc = $x_calc + $term;
# end inner do
# last if (10.0*(2.0**$x_calc) > 1600.0);
}} until (10.0*(2.0**$x_calc) > 1600.0);
$x_calc = $penultimate;
# end outer do
}} until ($power > 35);
$x_calc = $penultimate;
print STDOUT "x_calc output is $x_calc\n";
print STDOUT "x_sought output is $x_sought\n";
print STDOUT "sig figs output is 1.23456789112345 $cows_come_home\n";
# perl contract68.pl
# perl contract68.pl 2>text55.txt >text56.txt
__END__
#end script begin output
term is 0.5
current is -0.00057
term is 0.25
current is 7.3
term is 0.125
current is 7.3
term is 0.0625
current is 7.3
term is 0.03125
current is 7.3
term is 0.015625
current is 7.3
term is 0.0078125
current is 7.315625
term is 0.00390625
current is 7.315625
term is 0.001953125
current is 7.31953125
term is 0.0009765625
current is 7.321484375
term is 0.00048828125
current is 7.321484375
term is 0.000244140625
current is 7.321484375
term is 0.0001220703125
current is 7.321728515625
term is 6.103515625e-005
current is 7.3218505859375
term is 3.0517578125e-005
current is 7.32191162109375
term is 1.52587890625e-005
current is 7.32191162109375
term is 7.62939453125e-006
current is 7.32192687988281
term is 3.814697265625e-006
current is 7.32192687988281
term is 1.9073486328125e-006
current is 7.32192687988281
term is 9.5367431640625e-007
current is 7.32192687988281
term is 4.76837158203125e-007
current is 7.32192783355713
term is 2.38418579101563e-007
current is 7.32192783355713
term is 1.19209289550781e-007
current is 7.32192807197571
term is 5.96046447753906e-008
current is 7.32192807197571
term is 2.98023223876953e-008
current is 7.32192807197571
term is 1.49011611938477e-008
current is 7.32192807197571
term is 7.45058059692383e-009
current is 7.32192808687687
term is 3.72529029846191e-009
current is 7.32192809432745
term is 1.86264514923096e-009
current is 7.32192809432745
term is 9.31322574615479e-010
current is 7.32192809432745
term is 4.65661287307739e-010
current is 7.32192809432745
term is 2.3283064365387e-010
current is 7.32192809479311
term is 1.16415321826935e-010
current is 7.32192809479311
term is 5.82076609134674e-011
current is 7.32192809479311
term is 2.91038304567337e-011
current is 7.32192809485132
x_calc output is 7.32192809488042
x_sought output is 7.32192809488736
sig figs output is 1.23456789112345 0
#end output begin comment
I hope that aligns.
I'll try to beautify with those same changes as you made above. Thx.
--
wade ward
wade@zaxfuuq.net
435 -838-7760
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
------------------------------
Date: Thu, 29 Nov 2007 04:40:31 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: equivalent controls
Message-Id: <3pr3j.18351$Mg1.4956@trndny03>
Wade Ward wrote:
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> ## contributors: joe smith, jean luc, Jürgen Exner
Please remove my name. I would be ashamed to be associated with such code.
jue
------------------------------
Date: Wed, 28 Nov 2007 23:41:45 -0700
From: "Wade Ward" <wade@zaxfuuq.net>
Subject: Re: equivalent controls
Message-Id: <1196318029_707@sp12lax.superfeed.net>
f'up reset
Vielleicht wollen wir uns lieber auf Deutsch unterhalten. Kannste bitte mal
op duuch erklaeren, was in Allerhäßlichkeit in diesem Program stattfindet?
Wird Dir leichter zu berlinern, wahr?
--
wade ward
wade@zaxfuuq.net
435 -838-7760
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:9Iq3j.17146$r81.5080@trndny05...
> Wade Ward wrote:
> [...]
>> do {{
>> $x_calc++;
>> $power++;
>>
>> last if $x_calc > 10;
>> print STDOUT "x calc is $x_calc\n";
>> print STDOUT "x_calc out is $x_calc\n";
>> print STDOUT "power out is $power\n";
>> do {{
>> $power++;
>> $x_calc++;
>> print STDOUT "power in is $power\n";
>> print STDOUT "x_calc in is $x_calc\n";
>> $x_sought = $x_sought - 1;
>> last if 1 > 0;
>> print STDOUT "x sought is $x_sought\n";
>>
>> }} until $x_calc > 7.5;
>> $x_calc = $penultimate;
>> }} until ($power > 6);
> [...]
>> Is there a slicker way to do this in perl than using the double curly
>> braces?
>
> Absolutely, here it goes for your main loop:
>
> while ($power < 6 and $x_calc < 10) {
> $x_calc++;
> $power++;
> print "x calc is $x_calc\n";
> print "x_calc out is $x_calc\n";
> print "power out is $power\n";
> while ($x_calc <= 7.5 ){
> $power++;
> $x_calc++;
> print "power in is $power\n";
> print "x_calc in is $x_calc\n";
> }
> $x_calc = $penultimate;
> };
>
> It also reduced the number of lines from 20 to 14 and IMHO is much more
> readable, too.
>
> jue
>
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
------------------------------
Date: Wed, 28 Nov 2007 18:22:34 -0800 (PST)
From: Jack <jack_posemsky@yahoo.com>
Subject: How to persist and query a hash lookup in memory with Perl ?
Message-Id: <007d08f6-8ae8-4286-ace4-dfacb56fb42b@i12g2000prf.googlegroups.com>
Hi I have a web application that needs to on an adhoc basis query a
hash lookup which should be persisted in memory - I have seen this
module "Persistent::Memory - A Persistent Class implemented using
Memory (RAM)" but I wanted to see if there was a much simpler approach
to taking a hash map and making it 'callable' while persisted in
memory using standard features not requiring a special Perl module
install..
Any thoughts would be appreciated.
Thanks,
Jack
------------------------------
Date: Thu, 29 Nov 2007 03:37:15 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to persist and query a hash lookup in memory with Perl ?
Message-Id: <5r6mr4F1392htU1@mid.individual.net>
Jack wrote:
> Hi I have a web application that needs to on an adhoc basis query a
> hash lookup which should be persisted in memory - I have seen this
> module "Persistent::Memory - A Persistent Class implemented using
> Memory (RAM)" but I wanted to see if there was a much simpler approach
> to taking a hash map and making it 'callable' while persisted in
> memory using standard features not requiring a special Perl module
> install..
>
> Any thoughts would be appreciated.
Why not a tied hash? See e.g. "perldoc DB_File".
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 28 Nov 2007 20:23:15 -0800 (PST)
From: jackposemsky@yahoo.com
Subject: Re: How to persist and query a hash lookup in memory with Perl ?
Message-Id: <7c5df670-d214-40c2-b59d-9ba1f5785618@s36g2000prg.googlegroups.com>
On Nov 28, 6:37 pm, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> Jack wrote:
> > Hi I have a web application that needs to on an adhoc basis query a
> > hash lookup which should be persisted in memory - I have seen this
> > module "Persistent::Memory - A Persistent Class implemented using
> > Memory (RAM)" but I wanted to see if there was a much simpler approach
> > to taking a hash map and making it 'callable' while persisted in
> > memory using standard features not requiring a special Perl module
> > install..
>
> > Any thoughts would be appreciated.
>
> Why not a tied hash? See e.g. "perldoc DB_File".
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl
Hi and thank you however that looks too complex - just trying to put a
hash in memory, why is that so hard to do ? Is there a simpler way ?
------------------------------
Date: Thu, 29 Nov 2007 05:26:36 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How to persist and query a hash lookup in memory with Perl ?
Message-Id: <Xns99F7480FD067asu1cornelledu@127.0.0.1>
jackposemsky@yahoo.com wrote in
news:7c5df670-d214-40c2-b59d-9ba1f5785618@s36g2000prg.googlegroups.com:
> On Nov 28, 6:37 pm, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
>> Jack wrote:
>> > Hi I have a web application that needs to on an adhoc basis query a
>> > hash lookup which should be persisted in memory - I have seen this
>> > module "Persistent::Memory - A Persistent Class implemented using
>> > Memory (RAM)" but I wanted to see if there was a much simpler
>> > approach to taking a hash map and making it 'callable' while
>> > persisted in memory using standard features not requiring a special
>> > Perl module install..
>>
>> > Any thoughts would be appreciated.
>>
>> Why not a tied hash? See e.g. "perldoc DB_File".
>>
>> --
>> Gunnar Hjalmarsson
>> Email:http://www.gunnar.cc/cgi-bin/contact.pl
Don't quote sigs.
> Hi and thank you however that looks too complex - just trying to put a
> hash in memory, why is that so hard to do ? Is there a simpler way ?
It looks like programming might be too hard for you.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
------------------------------
Date: Wed, 28 Nov 2007 20:16:14 -0800 (PST)
From: mike <rallabs@adelphia.net>
Subject: Re: making the keys of a hash from parameters collected from a form-2nd last line had an incorrect variable name. Sorry.
Message-Id: <e0904bcc-bb47-4fae-9c46-fff6a7a41ac4@d27g2000prf.googlegroups.com>
On Nov 28, 11:11 pm, mike <rall...@adelphia.net> wrote:
> Hello everyone:
> I have the need to prioritize a number of items from a list and then
> print them out in the order in which they were chosen. To be more
> specific, I have a list of 12 items and I would like to have the users
> indicate which is their first choice, which is their second, etc. up
> to 8. I must put the items into a file in the order which has been
> prioritized by the user. My thought was to present a form with 12
> textboxes, into which they can type the number '1' for their first
> choice, the number '2' for their second, etc. Then, when parsing the
> form, I could make a hash whose keys are the numbers put into the
> boxes, from 1 to 8, with the hash 'values' being the textbox 'names'.
> Sorting the hash according to keys would then give me the info I
> need. I find, however, that this approach is flawed in that the
> collected parameters from the forms are not in the proper format,
> apparently, for making into keys. A script or 2 is worth a zillion
> words, so I present scaled-down versions of the form and the parsing
> script, and if anyone has a solution I sure would like to hear it.
> The first script, 'mike.cgi' follows:
>
> #!/usr/bin/perl -wT
> use CGI::Carp qw(fatalsToBrowser);
> use CGI qw(:standard -no_xhtml);
> use strict;
> use diagnostics;
> my $q = new CGI;
> print $q->header;
> print $q->start_html(-title=>"mike.cgi",-bgcolor=>"silver",-
> text=>"blue",-link=>"blue"),$q->br,$q->br,$q->br;
> print $q->h3("Please indicate your favorite fruit with a '1', and your
> second favorite with a '2'. \n");
> print $q->h3("Leave the rest blank:\n");
> print $q->start_form(-method=>"POST", -action=>"parse.cgi");
> print $q->start_form(-method=>"POST", -action=>"getparam.cgi");
> print $q->h3(textfield(-name=>'app', -size=>1),"apple");
> print $q->h3(textfield(-name=>'ora', -size=>1),"orange");
> print $q->h3(textfield(-name=>'lem', -size=>1),"lemon");
> print $q->h3(textfield(-name=>'lim', -size=>1),"lime");
> print $q->h3(textfield(-name=>'ban', -size=>1),"banana");
> print $q->submit, $q->reset, $q->endform, end_html;
> exit;
>
> The script that is supposed to make and sort the hash is called
> 'parse.cgi':
> #!/usr/bin/perl -wT
> use CGI::Carp qw(fatalsToBrowser);
> use CGI qw(:standard -no_xhtml);
> use strict;
> use diagnostics;
> my $q = new CGI;
> print $q->header;
> print $q->start_html(-title=>"mike.cgi",-bgcolor=>"silver",-
> text=>"blue",-link=>"blue"),$q->br,$q->br,$q->br;
> my %hashfruit=(
> "param('app')"=>'app',
> "param('lem')"=>'lem',
> "param('ora')"=>'ora',
> "param('lem')"=>'lem',
> "param('lim')"=>'lim',
> );
> my $k;
> foreach $k (keys %hashfruit){
> print "<P> The key is: <b> $k </b> and the value is <b>
> $hashfruit{$k}</b>";
> }
> end_html; exit;
>
> As you can see, the 'keys' were intended to be the values of
> parameters passed to 'parse.cgi', but instead of getting the values (1
> and 2), I get as keys the strings 'param(app)' etc. Does anyone
> know how to get the actual contents the user typed in so I can use
> them as the keys to %hashfruit? Thanks in advance.
> Mike
------------------------------
Date: Wed, 28 Nov 2007 20:11:08 -0800 (PST)
From: mike <rallabs@adelphia.net>
Subject: making the keys of a hash from parameters collected from a form
Message-Id: <35f36fbc-c724-4df0-a418-840e48f9895e@n20g2000hsh.googlegroups.com>
Hello everyone:
I have the need to prioritize a number of items from a list and then
print them out in the order in which they were chosen. To be more
specific, I have a list of 12 items and I would like to have the users
indicate which is their first choice, which is their second, etc. up
to 8. I must put the items into a file in the order which has been
prioritized by the user. My thought was to present a form with 12
textboxes, into which they can type the number '1' for their first
choice, the number '2' for their second, etc. Then, when parsing the
form, I could make a hash whose keys are the numbers put into the
boxes, from 1 to 8, with the hash 'values' being the textbox 'names'.
Sorting the hash according to keys would then give me the info I
need. I find, however, that this approach is flawed in that the
collected parameters from the forms are not in the proper format,
apparently, for making into keys. A script or 2 is worth a zillion
words, so I present scaled-down versions of the form and the parsing
script, and if anyone has a solution I sure would like to hear it.
The first script, 'mike.cgi' follows:
#!/usr/bin/perl -wT
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard -no_xhtml);
use strict;
use diagnostics;
my $q = new CGI;
print $q->header;
print $q->start_html(-title=>"mike.cgi",-bgcolor=>"silver",-
text=>"blue",-link=>"blue"),$q->br,$q->br,$q->br;
print $q->h3("Please indicate your favorite fruit with a '1', and your
second favorite with a '2'. \n");
print $q->h3("Leave the rest blank:\n");
print $q->start_form(-method=>"POST", -action=>"parse.cgi");
print $q->start_form(-method=>"POST", -action=>"getparam.cgi");
print $q->h3(textfield(-name=>'app', -size=>1),"apple");
print $q->h3(textfield(-name=>'ora', -size=>1),"orange");
print $q->h3(textfield(-name=>'lem', -size=>1),"lemon");
print $q->h3(textfield(-name=>'lim', -size=>1),"lime");
print $q->h3(textfield(-name=>'ban', -size=>1),"banana");
print $q->submit, $q->reset, $q->endform, end_html;
exit;
The script that is supposed to make and sort the hash is called
'parse.cgi':
#!/usr/bin/perl -wT
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard -no_xhtml);
use strict;
use diagnostics;
my $q = new CGI;
print $q->header;
print $q->start_html(-title=>"mike.cgi",-bgcolor=>"silver",-
text=>"blue",-link=>"blue"),$q->br,$q->br,$q->br;
my %hashfruit=(
"param('app')"=>'app',
"param('lem')"=>'lem',
"param('ora')"=>'ora',
"param('lem')"=>'lem',
"param('lim')"=>'lim',
);
my $k;
foreach $k (keys %hashfruit){
print "<P> The key is: <b> $k </b> and the value is <b>
$hashfruit{$key}</b>";
}
end_html; exit;
As you can see, the 'keys' were intended to be the values of
parameters passed to 'parse.cgi', but instead of getting the values (1
and 2), I get as keys the strings 'param(app)' etc. Does anyone
know how to get the actual contents the user typed in so I can use
them as the keys to %hashfruit? Thanks in advance.
Mike
------------------------------
Date: Thu, 29 Nov 2007 05:23:28 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: making the keys of a hash from parameters collected from a form
Message-Id: <Xns99F73F96CCA7asu1cornelledu@127.0.0.1>
mike <rallabs@adelphia.net> wrote in news:35f36fbc-c724-4df0-a418-
840e48f9895e@n20g2000hsh.googlegroups.com:
> Hello everyone:
> I have the need to prioritize a number of items from a list and then
> print them out in the order in which they were chosen. To be more
> specific, I have a list of 12 items and I would like to have the users
> indicate which is their first choice, which is their second, etc. up
> to 8. I must put the items into a file in the order which has been
> prioritized by the user.
...
> print $q->h3(textfield(-name=>'app', -size=>1),"apple");
A textfield in h3? We're straying off-topic here but that is awful HTML.
> my %hashfruit=(
> "param('app')"=>'app',
> "param('lem')"=>'lem',
> "param('ora')"=>'ora',
> "param('lem')"=>'lem',
> "param('lim')"=>'lim',
...
> instead of getting the values (1
> and 2), I get as keys the strings 'param(app)'
You are specifying the keys as strings in the form "param('app')"
yourself. That's what you told your program to do. How do you expect
anything else to happen?
If, instead, you had used
my %hashfruit=(
param('app') =>'app',
param('lem') =>'lem',
param('ora') =>'ora',
param('lem') =>'lem',
param('lim') =>'lim',
);
the results of the param calls would be stringified.
Of course, you are not performing any sanity checks on the inputs so
this has the potential of becoming problematic. By giving each textfield
a different name, you are making life unnecessarily hard.
Instead, use the same name, say 'rank', for all the textfields. That
way, things like checking that all the ranks are distinct, all the ranks
are numbers etc becomes a much easier operation and you don't have to
make a whole bunch of changes every time you change the list of fruits.
As your scripts are too messy to modify, here is an alternative:
#!perl
use strict;
use warnings;
use CGI qw( -no_xhtml );
my @FRUITS = qw( apple orange lemon lime banana );
my $cgi = CGI->new;
print $cgi->header( 'text/html' );
unless ( $cgi->param ) {
show_form( $cgi );
}
else {
process_form( $cgi );
}
sub show_form {
my $cgi = shift;
my ( $msg ) = @_;
print $cgi->start_html;
if ( $msg ) {
print $cgi->p( $cgi->em( $msg ) );
}
print $cgi->start_form( -method => 'GET' );
for my $fruit ( @FRUITS ) {
print $cgi->p(
$cgi->textfield( -name => 'rank', -size => 1 ), $fruit
);
}
print $cgi->p( $cgi->submit, $cgi->reset ),
$cgi->end_form,
$cgi->end_html;
return;
}
sub process_form {
my $cgi = shift;
my @ranks = $cgi->param( 'rank' );
for my $rank ( @ranks ) {
$rank =~ s/^\s+//;
$rank =~ s/\s+$//;
unless ( $rank =~ /^(\d+)$/
and $rank => 1
and $rank <= @FRUITS
) {
return show_form(
$cgi,
sprintf(
'Ranks must be integers between %d and %d.',
1, scalar @FRUITS
)
);
}
}
my %ranked;
@ranked{ @ranks } = @FRUITS;
unless ( keys %ranked == @FRUITS ) {
return show_form(
$cgi,
'Please fill in all spaces with distinct ranks.'
);
}
print $cgi->start_html,
$cgi->ol(
$cgi->li(
[ map { $ranked{ $_ } } sort keys %ranked ]
)
),
$cgi->end_html;
return;
}
__END__
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
------------------------------
Date: Thu, 29 Nov 2007 05:42:16 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Thu Nov 29 2007
Message-Id: <Js96IG.Gso@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
Bundle-NICAT-0.01
http://search.cpan.org/~marcel/Bundle-NICAT-0.01/
Prerequisites for the Austrian Domain Registry projects
----
Bundle-NICAT-0.02
http://search.cpan.org/~marcel/Bundle-NICAT-0.02/
Prerequisites for the Austrian Domain Registry projects
----
Business-TW-TSIB-VirtualAccount-0.04
http://search.cpan.org/~cornelius/Business-TW-TSIB-VirtualAccount-0.04/
Module for Taishin Bank Virtual Account Management
----
CGI-FileUpload-0.01
http://search.cpan.org/~alexmass/CGI-FileUpload-0.01/
A module to upload file through CGI asynchrnously, know where the upload status and get back the file from a third parties on the server
----
Cal-DAV-0.5
http://search.cpan.org/~simonw/Cal-DAV-0.5/
a CalDAV client
----
Catalyst-Controller-Atompub-0.2.2
http://search.cpan.org/~takeru/Catalyst-Controller-Atompub-0.2.2/
A Catalyst controller for the Atom Publishing Protocol
----
Catalyst-Model-SOAP-0.0.1
http://search.cpan.org/~druoso/Catalyst-Model-SOAP-0.0.1/
Map a WSDL to a catalyst model class.
----
Data-Storage-0.05
http://search.cpan.org/~marcel/Data-Storage-0.05/
generic abstract storage mechanism
----
Date-Components-v0.0.1
http://search.cpan.org/~dmac/Date-Components-v0.0.1/
Parses, processes and formats ONLY dates and date components (time parameters are ignored).
----
Devel-FindRef-1.0
http://search.cpan.org/~mlehmann/Devel-FindRef-1.0/
where is that reference to my scalar hiding?
----
Devel-PerlySense-0.0130
http://search.cpan.org/~johanl/Devel-PerlySense-0.0130/
IntelliSense for Perl
----
EV-1.5
http://search.cpan.org/~mlehmann/EV-1.5/
perl interface to libev, a high performance full-featured event loop
----
ExtUtils-MakeMaker-6.38
http://search.cpan.org/~mschwern/ExtUtils-MakeMaker-6.38/
Create a module Makefile
----
Fuse-PDF-0.07
http://search.cpan.org/~cdolan/Fuse-PDF-0.07/
Filesystem embedded in a PDF document
----
Games-Tournament-Swiss-0.15
http://search.cpan.org/~drbean/Games-Tournament-Swiss-0.15/
FIDE Swiss Same-Rank Contestant Pairing
----
HTTP-Cookies-Mozilla-1.13
http://search.cpan.org/~bdfoy/HTTP-Cookies-Mozilla-1.13/
Cookie storage and management for Mozilla
----
Hash-Inflator-0.01
http://search.cpan.org/~marcel/Hash-Inflator-0.01/
Access hash entries through methods
----
Imager-0.61_02
http://search.cpan.org/~tonyc/Imager-0.61_02/
Perl extension for Generating 24 bit Images
----
Imager-Montage-0.01b
http://search.cpan.org/~cornelius/Imager-Montage-0.01b/
montage images
----
Imager-Montage-0.02
http://search.cpan.org/~cornelius/Imager-Montage-0.02/
montage images
----
Infobot-0.91_02
http://search.cpan.org/~sargie/Infobot-0.91_02/
Developer's Overview
----
Infobot-0.91_03
http://search.cpan.org/~sargie/Infobot-0.91_03/
Developer's Overview
----
Linux-BootCleanup-0.01
http://search.cpan.org/~kerisman/Linux-BootCleanup-0.01/
clean up old kernel files in /boot and update bootloader menu entries accordingly
----
Linux-BootCleanup-0.02
http://search.cpan.org/~kerisman/Linux-BootCleanup-0.02/
clean up old kernel files in /boot and update bootloader menu entries accordingly
----
Log-Dynamic-0.04
http://search.cpan.org/~jconerly/Log-Dynamic-0.04/
OOish dynamic and customizable logging
----
MARC-XML-0.88
http://search.cpan.org/~kados/MARC-XML-0.88/
----
Mail-Box-2.079
http://search.cpan.org/~markov/Mail-Box-2.079/
manage a mailbox, a folder with messages
----
Mail-IMAPClient-3.00
http://search.cpan.org/~markov/Mail-IMAPClient-3.00/
An IMAP Client API
----
MailTools-2.01
http://search.cpan.org/~markov/MailTools-2.01/
----
MooseX-Types-Path-Class-0.03
http://search.cpan.org/~thepler/MooseX-Types-Path-Class-0.03/
A Path::Class type library for Moose
----
Net-EPP-Frame-0.10
http://search.cpan.org/~gbrown/Net-EPP-Frame-0.10/
An EPP XML frame system built on top of XML::LibXML.
----
Net-EPP-Simple-0.01
http://search.cpan.org/~gbrown/Net-EPP-Simple-0.01/
a simple EPP client interface for the most common jobs
----
Net-Flow-0.01_r
http://search.cpan.org/~akoba/Net-Flow-0.01_r/
decode and encode NetFlow/IPFIX datagrams.
----
Net-Jifty-0.03
http://search.cpan.org/~sartak/Net-Jifty-0.03/
interface to online Jifty applications
----
OurCal-1.0
http://search.cpan.org/~simonw/OurCal-1.0/
a simple yet featureful personal calendaring system
----
POE-Component-Client-FTP-0.09
http://search.cpan.org/~bingos/POE-Component-Client-FTP-0.09/
Implements an FTP client POE Component
----
Rose-HTML-Objects-0.550_05
http://search.cpan.org/~jsiracusa/Rose-HTML-Objects-0.550_05/
Object-oriented interfaces for HTML.
----
Sepia-0.95_02
http://search.cpan.org/~seano/Sepia-0.95_02/
Simple Emacs-Perl Interface
----
Signal-StackTrace-0.04
http://search.cpan.org/~lembark/Signal-StackTrace-0.04/
install signal handler to print a stacktrace.
----
Text-CSV-1.00
http://search.cpan.org/~makamaka/Text-CSV-1.00/
comma-separated values manipulator (using XS or PurePerl)
----
Time-HiRes-1.9709
http://search.cpan.org/~jhi/Time-HiRes-1.9709/
High resolution alarm, sleep, gettimeofday, interval timers
----
UNIVERSAL-derived_classes-0.02
http://search.cpan.org/~tamashiro/UNIVERSAL-derived_classes-0.02/
Returns derived classes of a class
----
arclog-3.01
http://search.cpan.org/~imacat/arclog-3.01/
Archive the log files monthly
----
podlators-2.0.6
http://search.cpan.org/~rra/podlators-2.0.6/
----
slackget10-0.12c
http://search.cpan.org/~dupuisarn/slackget10-0.12c/
The main slack-get 1.0 library
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Thu, 29 Nov 2007 02:37:55 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: page 124 of the camel book
Message-Id: <x7ve7lydx8.fsf@mail.sysarch.com>
>>>>> "WW" == Wade Ward <wade@zaxfuuq.net> writes:
WW> do {{
WW> $x_calc = $x_calc - 1;
ever heard of --?
WW> # last if $x_calc < 0;
WW> print STDOUT "x calc is $x_calc\n";
WW> do {{
WW> $x_sought = $x_sought - 1;
WW> # last if $x_sought < 0;
WW> print STDOUT "x sought is $x_sought\n";
WW> }} until $x_sought < 0;
WW> }} until $x_calc < 0;
do while is bad enough in perl (rarely needed, i never use it) but
do/until is horrible. invert those boolean tests and use while. but
better would be to invert those into proper while loops.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 1078
***************************************