[13181] in Perl-Users-Digest
Perl-Users Digest, Issue: 591 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 19 15:12:56 1999
Date: Thu, 19 Aug 1999 12:10:17 -0700 (PDT)
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, 19 Aug 1999 Volume: 9 Number: 591
Today's topics:
Re: Python for Perl users: random thoughts <meowing@banet.net>
Re: Question about date (Doran L. Barton)
Split comp.lang.perl.misc <jyoyoliu@hotmail.com>
Re: Split comp.lang.perl.misc <kperrier@blkbox.com>
Re: system or exec??? Many defunct processes... <rootbeer@redcat.com>
Re: Testing if a module is installed <rootbeer@redcat.com>
Re: Testing if a module is installed <toby@venice.cas.utk.edu>
Re: Testing if a module is installed <CTauss@hotmail.com>
voting system pealse advise <marlee@en.com>
Re: Wacky Programming Tales <keithmur@mindspring.com>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 19 Aug 1999 14:46:16 -0400
From: meow <meowing@banet.net>
Subject: Re: Python for Perl users: random thoughts
Message-Id: <87btc3d2x3.fsf@banet.net>
Just some fill-ins/updates.
Tom Christiansen <tchrist@mox.perl.com> wrote:
> GOTCHA: (low)
> I don't understand why we have so many C operators, such as "&" and
> "|" and "~", but we don't have "&&" or "||" or "!"
But Perl does something useful with the different spellings of, for
example, `&&' and `and' by giving them different precendence. There
wouldn't be much sense in having both if they were merely synonyms.
> We also have "<<" and ">>". It's bizarre that the relational
> and "?:" are missing. Python uses so much from C to make people
> see what they expect to see, but this is missing. Why?
Over there, the overall meme tends to be something like "if TMTOWTDI,
there'd better be a damn good reason." So, a?b:c would need to have
some nifty property that couldn't be accomplished by if: else: to show
up. It's a religious issue.
> COOLNESS:
> Python's "longs" are actually built-in, arbitrary precision
> integers (i.e. BigInts)
But add a gotcha: Longs mostly mix in pretty well with functions
originally written to deal with ints, but weird things can happen if,
for example, you have string conversions in there and hadn't accounted
for the L suffix.
> DISSIMILARITY:
> There are no private variables in a module or a class.
> They can always be fully-qualified and accessed from
> without.
Names in the form __foo are private. You can still get at them, but
the necessary contortions will limit their use to people bent on doing
Evil Things. For example:
class Thingy:
__foo = 3.3
spork = Thingy()
print spork.__foo # trips an AttributeError, but the rather odd...
print spork._Thingy__foo # prints 3.3
Again, this is religion; IIRC Guido refers to it as "advisory locking."
> GOTCHA: (high)
> As we saw with lists, because everything is a reference, and there's
> no way to dereference that reference, this means that again there
> is also no built-in, intuitive way to copy a dictionary. Instead,
> the suggested work-around is to write a loop:
> new = {}
> for key in old.keys:
> new[key] = old[key]
> But this is guaranteed slower, because it's not at the C level.
newdict = olddict.copy()
This would be way cooler if the method existed for other types too;
instead you would pull in the copy module for them.
> GOTCHA: (medium)
> There's no way to set up a permitted exports list. The caller may have
> anything they ask for.
Not quite, it's more that the defaults are approximately reversed.
`from thingy import *' is about the same as a use with most everything in
@EXPORT.
If some of the names in thingy begin with `_', it's as if Perl left them
out of @EXPORT.
If names in thingy begin with `__', it's like when a Perl module
doesn't put them in @EXPORT_OK. (names that also *end* with `__' are
reserved names and treated a bit differently.)
> GOTCHA: (medium)
> You can't cut and paste these examples because of the issue
> of white space significance. :-(
Sure you can, but pity the soul who wants to use an editor without a
Python mode. In emacs it's just C-c > and C-c <, in something like
pico you're screwed.
> GOTCHA: (high)
> There doesn't seem to be away other than using low-level hand-rolling
> of posix functions to supply things like os.popen and os.system
> a list of shell-proof arguments. Looks like it always goes through the
> shell. This has security ramifications.
Yup. OTOH, it's nice to have fine control over it with the whole
execl/execv family available.
> GOTCHA: (medium)
> Anything that python doesn't like, it raises an exception about.
> There is no fail-soft. Even non-exception issues raise exceptions.
> It's pervasive. K&P curse languages that force people who want
> to open() a file to wrap everything in exception code, saying that
> "failing to open a file is hardly exceptional".
OTOH, post an open without `|| die $!;' to clp.misc and see if you'll
get away with it ;)
> GOTCHA: (low)
> I can't figure out how to write a class destructor for at exit
> handling the way I can with Perl's END{}
sys.exitfunc is probably what you would want.
------------------------------
Date: 19 Aug 1999 12:41:10 -0600
From: fozz@xmission.xmission.com (Doran L. Barton)
Subject: Re: Question about date
Message-Id: <7phj46$c9k$1@xmission.xmission.com>
Seth David Johnson <sjohns17@uic.edu> writes:
>On 19 Aug 1999, Jimtaylor5 wrote:
>> Can anyone tell me how I would check a date to see if two or more days have
>> passed? For example I tried taking the standard date time
>> (Mon Aug 16 21:57:34 1999) splitting it, matching, and incrimenting, which of
>> course doesn't work consistently.
>Not that I'd use a formatted time for this, but I'd wager it's possible
>to parse it in a workable manner. However, read below.
>> Has anyone done this check with any of their
>> programs or can show me a way to accurately check if a couple days have passed?
>Read the perlfunc pod, specifically the part about "localtime." :)
I would strongly suggest the use of Date::Manip here. Use the
ParseDateDelta() sub to find the distance (in time) between two time/date
values. Very very helpful indeed.
-=Fozz
--
Doran L. Barton = fozz@xmission.com && http://www.xmission.com/~fozz/
** Dynamic web developer, Perl hacker. Using the Internet since 1990. **
"I have learned much more about Microsoft by using the Linux operating
system than I ever would have done by using Windows." - Neal Stephenson
------------------------------
Date: Thu, 19 Aug 1999 12:55:32 -0500
From: "James Liu" <jyoyoliu@hotmail.com>
Subject: Split comp.lang.perl.misc
Message-Id: <DvXu3.1342$PY.114135@news.corecomm.net>
There really should be more perl newsgroups. There are too many posts here.
I guess we could add
comp.lang.perl.reg
.io
.win32
.llama #for newbie posts. this one should
definately be moderated, with an automated look in FAQ response
.database
.otherlangs #for arguning about which langs are
better, discussing a2p s2p.
that should really clear up traffic and make finding what people want much
easier. please suggest others.
------------------------------
Date: 19 Aug 1999 13:46:20 -0500
From: Kent Perrier <kperrier@blkbox.com>
Subject: Re: Split comp.lang.perl.misc
Message-Id: <1670F218D915EF7D.ECA13E92EF861564.6DC150FA34162562@lp.airnews.net>
"James Liu" <jyoyoliu@hotmail.com> writes:
> There really should be more perl newsgroups. There are too many posts here.
With the smount of time that it took to get c.l.p.mod approved I wouldn't hold
your breath on any of these being actually created.
Kent
------------------------------
Date: Thu, 19 Aug 1999 11:14:58 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: system or exec??? Many defunct processes...
Message-Id: <Pine.GSO.4.10.9908191104340.17303-100000@user2.teleport.com>
On Thu, 19 Aug 1999, jethridge wrote:
> My problem is whenever I fork all of these processes, I end
> up with a bunch of zombie processes that will not go away
> until the parent process is killed off.
Have you seen the FAQ?
perlfaq8.pod:=head2 How do I avoid zombies on a Unix system?
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 19 Aug 1999 11:01:52 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Testing if a module is installed
Message-Id: <Pine.GSO.4.10.9908191042160.17303-100000@user2.teleport.com>
On Thu, 19 Aug 1999, toby wrote:
> So I want to use a module like Mail::Mailer or Net::SMTP. These
> modules are not installed on our system and the administrators do not
> want to install them for various reason (some valid; some not.)
If an admin can't or won't install software, what good is it? :-)
Replace, replace, replace. But, okay....
> I could go ahead and install the module without checking its prior
> existence, but this would cause every install of the script (for
> maintenance reasons or upgrades) to install the module again.
Besides, that wouldn't be polite. If they don't want a module installed,
the admins don't want your program installing it. If they do want it
installed, they can (and should) install it themselves.
But you could have users install your program using a Makefile.PL (in the
same way as standard modules on CPAN do). That program can check for a
module and even automate the installation by using the CPAN module.
> I am using this bit of code to test if a module exists:
>
> eval("use Net::SMTP"); if ($@) { ...do something about it ... }
Yessss, although that's possibly not the best way, in this case, since it
loads the module to no purpose. You can probably just search the @INC path
for the module you want - although it may be located elsewhere - and ask
the user's advice if it's not found ("Search harder / Install / Abort ?").
Of course, the module may be mis-installed....
Good luck with it!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 19 Aug 1999 14:17:39 -0400
From: toby <toby@venice.cas.utk.edu>
To: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Testing if a module is installed
Message-Id: <37BC4A43.5DD3D4C5@venice.cas.utk.edu>
Tom Phoenix wrote:
> On Thu, 19 Aug 1999, toby wrote:
>
> > So I want to use a module like Mail::Mailer or Net::SMTP. These
> > modules are not installed on our system and the administrators do not
> > want to install them for various reason (some valid; some not.)
>
> If an admin can't or won't install software, what good is it? :-)
> Replace, replace, replace. But, okay....
True. The curmudgeons here are afraid they may have to support it and they are
too busy to bother with questions about a module that consider non-standard.
>
>
> > I could go ahead and install the module without checking its prior
> > existence, but this would cause every install of the script (for
> > maintenance reasons or upgrades) to install the module again.
>
> Besides, that wouldn't be polite. If they don't want a module installed,
> the admins don't want your program installing it. If they do want it
> installed, they can (and should) install it themselves.
>
I mean install in a directory in the user's home directory. Like so:
shell$>perl Makefile.PL LIB=~/path_to_your_libraries
I would ask them though whether or not they (the users) wanted to have the
module installed. If not, tough toenails, you don't get to have the scripts
for the CGI. stuff.
>
> But you could have users install your program using a Makefile.PL (in the
> same way as standard modules on CPAN do). That program can check for a
> module and even automate the installation by using the CPAN module.
>
Yes. That is a consideration. I think you have put me on to a better way with
this.
>
> > I am using this bit of code to test if a module exists:
> >
> > eval("use Net::SMTP"); if ($@) { ...do something about it ... }
>
> Yessss, although that's possibly not the best way, in this case, since it
> loads the module to no purpose.
I guess that loading the module to see if the module is loadable serves a
purpose, but that is nit-picking. I guess this check would pass as OK, because
it could do no harm, could it?
>
>
> --
> Tom Phoenix Perl Training and Hacking Esperanto
> Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Toby
------------------------------
Date: 19 Aug 1999 14:24:53 -0500
From: "Chris Tauss" <CTauss@hotmail.com>
Subject: Re: Testing if a module is installed
Message-Id: <37bc4bf5@discussions>
toby <toby@venice.cas.utk.edu> wrote:
>
>
>I am using this bit of code to test if a module exists:
>
>eval("use Net::SMTP"); if ($@) { ...do something about it ... }
>
>Is there a better way to do this? (This is straight out of the
Camel) Or
>is this as practical as it gets?
>
>Toby
>
How about this on the command line:
perl -e "use Net::SMTP;"
If the module is not installed you will get a complaint. I use
this alot by manually typing it into the command line, but I
THINK using the backtick a-la
`perl -e "use Net::SMTP;"`
should produce a similiar effect.
------------------------------
Date: Thu, 19 Aug 1999 13:47:50 -0400
From: marlee <marlee@en.com>
Subject: voting system pealse advise
Message-Id: <37BC4346.3B83AB27@en.com>
hi,
i'm fairly new to using perl and I'm not quite sure what i'm doing. I
got this voting script from cgi-resource and i'm trying to modify it.
the original script was set up to tally votes using radio buttons so
that only one answer could be chosen. when results were calculated it
would add to the total of whichever choice was chosen. i am trying to
get it to use checkboxes instead and tally based on which boxes were
marked "yes". i have gotten it to add new choices successfully but i
can only get it to add to the total of each choice or not add to any i
can't seem to get it to determine which ones were checked. here is the
modified code below. i have put stars around the sections that
particulary interest me for this problem (a short section at the top and
the subs showvote and vote).
(i do realize that the subs FormatTop and FormatBottom are missing i
left them out on purpose even though they are reffered to in this code)
thanks alot to anyone who attempts to takle this problem.
marlee
#!/usr/local/bin/perl
# If you aren't going to put the data directory in the same directory as
this
# script, enter the server path (not the URL) to the data directory.
$data_path = "vote";
# if you don't want to allow your users to add their own topics, delete
the
# next line.
#$add_topic = 1;
# If you don't want to limit your users to voting only once, delete the
next
# line.
$onevote = -1;
# When creating a new topic, how many choices should I ask for? Note
that
# all of these choices do not need to be filled out.
$ask_choice = 100;
# Enter the title of your voting booth
$title = "WFNK 100 (or so)";
# What password do you want to use? This password will be required for
# deleting voting booths, options, and if you aren't allowing your users
# to add topics, adding topics.
$password = "???????????????";
##############################################################################
# Congratulations! You've finished defining the variables. If you want
to, #
# you can continue screwing with the script, but it isn't
necessary. #
##############################################################################
*********************************************************************************
*# Put the posted data into
variables *
*
*
*if ($ENV{"REQUEST_METHOD"} eq 'GET') { $buffer = $ENV{'QUERY_STRING'};
} *
*else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
} *
*@pairs = split(/&/,
$buffer); *
*foreach $pair (@pairs)
{ *
* ($name, $value) = split(/=/,
$pair); *
* $value =~ tr/+/
/; *
* $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",
hex($1))/eg; *
* $FORM{$name} =
$value; *
*}
*
*********************************************************************************
# Get the topics
open(DATA, "$data_path/vote.txt");
@data = <DATA>;
close(DATA);
# Decide what to do based on the $FORM{'action'} variable
print "Content-type: text/html\n\n";
if ($FORM{'action'} eq "admin") { &admin; }
elsif ($FORM{'action'} eq "add_topic") { &add_topic; }
elsif ($FORM{'action'} eq "showvote") { &showvote; }
elsif ($FORM{'action'} eq "others") { &others; }
elsif ($FORM{'action'} eq "vote") { &vote; }
elsif ($FORM{'action'} eq "results") { &results; }
elsif ($FORM{'action'} eq "delete") { &delete; }
else {
&FormatTop;
foreach $line(@data) {
($topic, $num, $others) = split(/\|/,
$line);
print "<b>$topic</b>";
$i = 0;
if ($onevote) {
open (FILE, "$data_path/ip$num.txt");
@ips = <FILE>;
close(FILE);
foreach $ip(@ips) {
chomp($ip);
if ($ip eq $ENV{'REMOTE_ADDR'}) { $i =
1; }
}
}
if ($i == 0) {
print "<form method=\"GET\">\n";
print "<input type=\"hidden\" name=\"action\"
value=\"showvote\">\n";
print "<input type=\"hidden\" name=\"topic\"
value=\"$num\"><td width=\"50\">\n";
print "<input type=\"submit\" value=\" Vote!
\"></td></form>\n";
}
else { print "<td width=\"50\">Already Voted</td>\n"; }
print "<form method=\"GET\">\n";
print "<input type=\"hidden\" name=\"action\"
value=\"results\">\n";
print "<input type=\"hidden\" name=\"topic\"
value=\"$num\">\n";
print "<td width=\"50\"><input type=\"submit\" value=\"
Results \"></td></form>\n";
print "</tr>\n";
}
if (@data) { print "</table></td></tr></table></center>\n"; }
if ($add_topic) { &addtopic; }
print "<center>Administration<form method=\"POST\"></center>\n";
print "<table cols=\"2\"><tr><td
align=\"right\">Password:</td>\n";
print "<td><input type=\"password\"
name=\"password\"></td></tr></table>\n";
print "<input type=\"hidden\" name=\"action\"
value=\"admin\"><center>\n";
print "<input type=\"submit\" value=\"Go to
Admin\"></form></center>\n";
&FormatBottom;
exit;
}
sub checkpassword {
if ($FORM{'password'} eq "") {
print "<html><head><title>Password Required</title>\n";
print "</head><body><h1>Password Required</h1>I'm
sorry,\n";
print "but you need a password to do that.\n";
exit;
}
elsif ($FORM{'password'} ne $password) {
print "<html><head><title>Bad
Password</title></head><body>\n";
print "<h1>Bad Password</h1>I'm sorry, but the password
you entered,\n";
print "<i>$FORM{'password'}</i>, is incorrect.";
exit;
}
}
sub addtopic {
print "<center><hr width=\"300\"></center>\n";
print "<a name=\"add_topic\"><h2>Add a topic:</h2></a>\n";
print "<center><table width=\"500\" border=\"5\"><tr><td>\n";
print "<form method=\"POST\"><input type=\"hidden\"
name=\"action\"";
print " value=\"add_topic\"><table cols=\"2\"><tr>\n";
print "<td align=\"right\">What question do you want\n";
print "people to vote on?</td><td><input type=\"text\"";
print " name=\"topic\"></td></tr>\n";
for ($i = 0; $i < $ask_choice; $i++) {
print "<tr><td align=\"right\">Enter a possible\n";
print "choice, or leave this field blank:</td><td>\n";
print "<input type=\"text\" name=\"$i\"></td></tr>\n";
}
print "<tr><td align=\"right\">Allow other's to add
choices?</td><td>\n";
print "<input type=\"radio\" name=\"others\" value=\"yes\"
CHECKED>Yes\n";
print "<input type=\"radio\" name=\"others\"
value=\"no\">No</td></tr>\n";
print "<tr><td align=\"right\"><input type=\"submit\"></td>\n";
print "<td><input type=\"reset\"></td></tr><input
type=\"hidden\"";
print " name=\"password\"
value=\"$FORM{'password'}\"></form>\n";
print "</table></td></tr></table></center>\n";
}
sub add_topic {
unless ($add_topic) { &checkpassword; }
# Make sure a topic was given
unless ($FORM{'topic'}) {
print "<html><head><title>Nice topic, genius
boy.</title></head>\n";
print "<body><h1>Question Missing</h1>Please click back
and try\n";
print "again.</body></html>\n";
exit;
}
# Make sure that at least one choice was given
$j = 0;
for ($i = 0; $i < $ask_choice; $i++) { if ($FORM{$i}) { $j++; }
}
if ($j == 0) {
print "<html><head><title>Please add at least one
choice</title>\n";
print "</head><body><h1>Please add a choice</h1>You need
to either\n";
print "add a choice or allow others to add choices.
Please click\n";
print "back and try again.\n";
exit;
}
# Add the topic to the main data
($i, $lastnum, $j) = split(/\|/, $data[$#data]);
$lastnum++;
open (FILE,">>$data_path/vote.txt");
print FILE "$FORM{'topic'}|$lastnum|$FORM{'others'}\n";
close(FILE);
$FORM{'topic'} = $lastnum;
open (FILE,">$data_path/ch$lastnum.txt");
$num = 0;
for ($i = 0; $i < $ask_choice; $i++) {
if ($FORM{$i}) {
print FILE "$FORM{$i}|0|$num\n";
$num++;
}
}
close(FILE);
print "<html><head><title>Topic Added</title>\n";
print "</head><body><h1>Topic Added</h1>Please click back and
hit reload.\n";
}
sub admin {
&checkpassword;
print
"<html><head><title>Administration</title></head><body>\n";
print "<center><a
href=\"http://www.cgi-resources.com/rate?01824\">Rate this Script @ The
CGI Resource Index</a></center>\n";
print "<h1>Administration</h1>\n";
# If there are any topics, print them out for deletion and allow
you
# to add and remove user's ability to add choices.
if (@data) {
print "<h2>Delete Topic or Choice</h2><ul>\n<form
method=\"POST\">";
print "\n<input type=\"hidden\" name=\"action\"
value=\"delete\">\n";
for ($i = 0; $i <= $#data; $i++) {
($topic, $numt, $others) =
split(/\|/,$data[$i]);
print "<input type=\"checkbox\" name=\"$i\"
value=\"-1\">$topic<ul>\n";
open (FILE, "$data_path/ch$numt.txt");
@choices = <FILE>;
close(FILE);
for ($j = 0; $j <= $#choices; $j++) {
($name,$votes,$numc) = split(/\|/,
$choices[$j]);
print "<li><input type=\"checkbox\"
name=\"$i" . "X$j\" value=\"-1\">$name (<i>$votes votes</i>)\n";
}
print "</ul>\n";
}
print "</ul><input type=\"hidden\" name=\"password\"
value=\"$FORM{'password'}\">\n";
print "<input type=\"submit\" value=\" Delete
\"></form>\n";
print "<h2>Allow/Disallow adding
choices</h2><center><form method=\"POST\">\n";
print "<input type=\"hidden\" name=\"action\"
value=\"others\">\n";
print "<input type=\"hidden\" name=\"password\"
value=\"$FORM{'password'}\">\n";
print "<table border=\"5\" width=\"500\"><tr><td><table
cols=\"2\">\n";
foreach $line(@data) {
chomp($line);
($topic, $num, $others) = split(/\|/,$line);
print "<tr><td align=\"right\"
width=\"400\">$topic</td>";
print "<td width=\"100\"><input type=\"radio\"
name=\"$num\"";
print " value=\"yes\"";
if ($others eq "yes") { print " checked"; }
print ">Allow<input type=\"radio\" name=\"$num\"
value=\"no\" ";
if ($others eq "no") { print " checked"; }
print ">Disallow</td></tr>\n";
}
print "</table><center><input type=\"submit\"><input
type=\"reset\"></form></td></tr></table>\n";
}
else { print "No topics to screw with.<p>\n"; }
&addtopic;
print "</body></html>\n";
exit;
}
sub others {
&checkpassword;
open (FILE, ">$data_path/vote.txt");
foreach $line(@data) {
($topic, $num, $others) = split(/\|/,$line);
print FILE "$topic|$num|$FORM{$num}\n";
}
close(FILE);
&admin;
}
*********************************************************************************
sub showvote {
# Get the information for the topic
foreach $line(@data) {
($topic,$num,$others) = split(/\|/, $line);
if ($num == $FORM{'topic'}) { last }
}
# print out the beginning of the page
print "<html><head><title>$topic</title></head><body>\n";
print
"<h1>$topic</h1>\n";
print "<center><table border=\"5\" width=\"500\"><tr><td><table
cols=\"2\">\n";
print "<form method=\"POST\"><input type=\"hidden\"
name=\"action\" ";
print "value=\"vote\">\n<input type=\"hidden\" name=\"topic\"
value=\"$num\">\n";
# print the choices
open(FILE,"$data_path/ch$num.txt");
@lines = <FILE>;
close(FILE);
$first = 0;
foreach $line(@lines) {
($choice, $x, $num) = split(/\|/, $line);
print "<tr><td width=\"10\"><input type=\"checkbox\"
name=\"$num\"";
print " value=\"yes\"";
print "></td><td width=\"490\"><b><i>$choice</i>";
print "</b></td></tr>\n";
}
if ($others eq "yes\n") {
print "<tr><td width=\"10\"><input type=\"checkbox\"
name=\"newchoice\"";
print " value=\"yes\"></td><td width=\"490\"><input
type=";
print "\"text\" name=\"entry\"></td></tr>\n";
}
print "</table><center><input type=\"submit\" value=\" Vote!
\"></center>\n";
print "</form></td></tr></table>\n";
exit;
}
sub vote {
if ($onevote) {
open (FILE, "$data_path/ip$FORM{'topic'}.txt");
@ips = <FILE>;
close(FILE);
foreach $ip(@ips) {
chomp($ip);
if ($ip eq $ENV{'REMOTE_ADDR'}) {
print "<html><head><title>Please only
vote once</title></head>\n";
print "<body><h1>Please only vote
once</h1>I'm sorry, but someone\n";
print "with the IP address
$ENV{'REMOTE_ADDR'} has already voted.\n";
print "Please click
back.</body></html>\n";
exit;
}
}
}
open (FILE, "$data_path/ch$FORM{'topic'}.txt");
@choices = <FILE>;
close(FILE);
if ($FORM{'newchoice'} eq "yes") {
unless ($FORM{'entry'}) {
print "<html><head><title>Missing
information</title><head><body>\n";
print "You've attempted to add another choice,
but you\n";
print "didn't fill out what that choice was
supposed to be!\n";
print "<p>Please click back and try
again</body></html>\n";
exit;
}
chomp($choices[$#choices]);
($x,$y,$last) = split(/\|/, $choices[$#choices]);
$last++;
open (FILE, ">>$data_path/ch$FORM{'topic'}.txt");
print FILE "$FORM{'entry'}|1|$last\n";
close(FILE);
if ($onevote) {
open (FILE,
">>$data_path/ip$FORM{'topic'}.txt");
print FILE "$ENV{'REMOTE_ADDR'}\n";
close(FILE);
}
&results;
}
open (FILE, ">$data_path/ch$FORM{'topic'}.txt");
foreach $choice(@choices) {
chomp($choice);
($x,$y,$last) = split(/\|/, $choice);
if ($FORM{'$last'} eq "yes") { $y++; }
print FILE "$x|$y|$last\n";
}
close(FILE);
if ($onevote) {
open (FILE, ">>$data_path/ip$FORM{'topic'}.txt");
print FILE "$ENV{'REMOTE_ADDR'}\n";
close(FILE);
}
&results;
}
*********************************************************************************
sub results {
foreach $line(@data) {
($topic, $num, $others) = split(/\|/,
$line);
if ($num eq $FORM{'topic'}) { last }
}
print "<html><head><title>$topic ::
Results</title></head><body>\n";
print "<h1>$topic</h1>\n";
print "<center><table width=\"500\" border=\"5\"><tr><td>\n";
print "<table cols=\"3\"><tr><td
width=\"400\"><center><b>Choice</b></td>\n";
print "<td width=\"50\"><center><b>Votes</b></center></td><td
width=\"50\">\n";
print "<center><b>%</b></center></td></tr>\n";
open (FILE, "$data_path/ch$FORM{'topic'}.txt");
@lines = <FILE>;
close(FILE);
$i = 0;
foreach $line(@lines) {
($topic,$votes,$num) = split(/\|/, $line);
$i = $i + $votes;
}
foreach $line(@lines) {
($topic,$votes,$num) = split(/\|/, $line);
if ($i > 0) { $percent = sprintf("%.2f",100 * ($votes /
$i)); }
else { $percent = "NA"; }
print "<tr><td width=\"400\"><i>$topic</i></td>";
print "<td width=\"50\"><i>$votes</i></td>";
print "<td width=\"50\"><i>$percent</i></td></tr>\n";
}
print "</table><center><form method=\"POST\"><input
type=\"submit\" value=\" Back to Main \">\n";
print "</form></center></td></tr></table></center>\n";
print "</body></html>\n";
exit;
}
sub delete {
&checkpassword;
for ($i = $#data; $i >= 0; $i--) {
($topic, $numt, $others) = split(/\|/,$data[$i]);
if ($FORM{$i})
{
unlink("$data_path/ch$numt.txt");
splice(@data,$i,1);
open (FILE,">$data_path/vote.txt");
foreach $line(@data) { print FILE "$line"; }
close(FILE);
}
else {
open(FILE, "$data_path/ch$numt.txt");
@choices = <FILE>;
close(FILE);
for ($j = $#choices; $j >= 0; $j--) {
$temp = "$i". "X$j";
if ($FORM{$temp}) {
splice(@choices,$j,1);
open(FILE,
">$data_path/ch$numt.txt");
foreach $line(@choices) { print
FILE "$line"; }
close(FILE);
}
}
}
}
print "<html><head><title>Deleted</title></head><body>\n";
print "<h1>Deleted</h1><form method=\"POST\">\n";
print "<input type=\"hidden\" name=\"action\"
value=\"admin\">\n";
print "<input type=\"hidden\" name=\"password\"
value=\"$FORM{'password'}\">\n";
print "Click <input type=\"submit\" value=\" this button \"> to
go back\n";
print "</form></body></html>\n";
exit;
}
------------------------------
Date: Thu, 19 Aug 1999 14:04:24 -0500
From: "Keith G. Murphy" <keithmur@mindspring.com>
Subject: Re: Wacky Programming Tales
Message-Id: <37BC5538.CEAFFA0F@mindspring.com>
Ben Caradoc-Davies wrote:
>
> [strange programming]
> The most confidence uninspiring piece of code I ever had the displeasure to
> maintain contained something like this (allegedly C++, but mainly it's
> intersection with C):
>
> i = 0;
> while( i < max_index ) {
> /* some copying or update (not modifying i) goes here */
> i = i + 1;
> }
>
> This was written by a *very* expensive consultant working for a large
> multinational accountancy firm.
>
I think I can explain this. The original code was written to compile
not under C++, but under a little known and short-lived language known
as "C=C+1". It was to C++ as Python is to Perl.
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. Due to their sizes, neither the Meta-FAQ nor
the FAQ are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq" from
almanac@ruby.oce.orst.edu.
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 V9 Issue 591
*************************************