Pual,
Do you just like to badger newbes or what?
You have not correctly identified the nature of Paul's followups.
It was not badgering, it was letting you in on the social dynamic
of this group of people that you just entered.
You've done a half dozen things that will be seen as rudeness by
many here.
One (probably too) common response to such a post is to killfile
your address, and ignore you forevermore, with you not even
knowing what has happened!
Another response is to make a followup pointing out these things
to you so that you would become aware of them before it is too late.
Which approach is more helpful to you?
Leaving you in ignorance, or helping you to learn what you
need to know to participate fully?
You were walking around with some toilet paper stuck to your shoe.
Many people just snickered at you, Paul was courteous enough to
say "Hey, you have some TP stuck to your shoe".
Now you are acting as if you _prefer_ not knowing.
I don't even get paid for
this.
Neither do we.
So we are not likely to write complete programs to specification,
that is what we do at work.
We don't write programs here. We help people write programs here.
I'm just a volunteer trying to help out for a good cause.
So are we.
(But "help out" is not the same as "do it for me".)
(and if your code leads to embarrassment for your client that makes
the 6 o'clock news, your "help out" may end up costing far more
than what was paid for the code.)
I sure hope not...
Maybe someone wanting to submit phone numbers
from a form to a text file with a cgi will run across this post and
not use the code in a cargo-cult manner, but will instead
work to understand what it does. (and then probably decide
to do it differently.)
save the hassle I went through.
I expect the root cause of your hassle was being new to four
different things all at the same time.
1) Usenet
2) web (CGI) programming
3) Perl
4) programmming itself (IMO)
Lurking or reading the Posting Guidelines or even googling
for "netiquette" would handle most of #1. (or simply listening
to the advice that Paul gave you.)
You can start on #2 with:
perldoc -q CGI
Where can I learn about CGI or Web programming in Perl?
What is the correct form of response from a CGI script?
My CGI script runs from the command line but not the browser.
(500 Server Error)
How can I get better error messages from a CGI program?
How do I make sure users can't enter values into a form that
cause my CGI script to do bad things?
How do I decode a CGI form?
You can start on #3 at learn.perl.org, and finish with asking
questions about Perl programming right here.
Learning industry standard programming practices (#4) is not
so easily addressed.
use warnings;
is a much better method of enabling warnings.
You should also enable strictures:
use strict;
to get perl to help you find common bugs.
Why did you include this module?
This is not a rhetorical question.
You never make use of any of the facilities that it provides,
so it looks like you are engaging in "cargo cult programming"
(using code even when you do not understand what it does).
Your programming life will be very hard unless we can
successfully teach you to understand code before using it.
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
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;}
}
my $phone = $FORM{phone};
If you do it like in the answer to the "How do I decode a CGI form?" FAQ,
then you can replace all of your code above with these 2 lines:
use CGI qw
standard);
my $phone = param( "phone" );
Not only is it a whole lot shorter, it does not contain the bugs
that your hand-rolled (and cargo-culted I would assume) code has.
flock (FILE, 2) or die "cannot lock file exclusively: $!";
^
^
You should avoid using system-dependent hard coded values like
that, since the numbers can be different on different systems.
You should import the constants from the Fcntl module instead:
use Fcntl qw
flock);
flock (FILE, LOCK_EX) or die ...
print FILE $phone . "\n";
You don't say what you are going to use this list of phone numbers
for, but in light of #2 above I better mention a couple more things
in case you haven't thought about them yet.
The web is a wild and wooly place. There are people out there that
just cruise around looking for an opportunity to cause trouble.
They will find opportunity aplenty if you put your "final code"
where they can find it.
What will your code do if a user enters this for the "phone" form value:
http://www.pornography.com
??
Do you _want_ to put that into your phone list? Probably not, so
you'd better do some input checking:
die 'does not look like a phone number' unless $phone =~/^[0-9 -]+$/;
(but don't use die() in a real CGI program...)
Yet another thing to consider: what if the user enters all of
his enemy's phone numbers instead of his own phone number?
Be careful out there!
[snip TOFU.
Yet another breach of standard netiquette...
]