[11000] in Perl-Users-Digest
Perl-Users Digest, Issue: 4600 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jan 9 02:01:12 1999
Date: Fri, 8 Jan 99 23:00:17 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 8 Jan 1999 Volume: 8 Number: 4600
Today's topics:
Re: "internal server error" <eugene@snailgem.org>
Re: a couple of beginner questions here. <eugene@snailgem.org>
Beginner trying to figure out PERL for cgi use <wayne@deerhurst.com>
Re: Convert textarea line wraps to print (Ronald J Kimball)
Re: determining controlling tty (Ronald J Kimball)
Re: geting arguments <eugene@snailgem.org>
Re: How do I find the path of the script calling me? (Tad McClellan)
Re: How to do an exact comparison? (Tad McClellan)
Memory Leak? <wcase@mediaone.net>
Re: output to multiple places... (Tad McClellan)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 08 Jan 1999 22:18:58 -0500
From: Eugene Sotirescu <eugene@snailgem.org>
To: Eirik Johansen <webpages@email.com>
Subject: Re: "internal server error"
Message-Id: <3696CAA2.F1FD85A5@snailgem.org>
Eirik,
change
$FORM{$recipient}
to
$FORM{'recipient'}
(you're not setting a $recipient variable after all).
Also the s/%40/@/ is not really necessary.
Eirik Johansen wrote:
> Who wants to learn Perl after feedback like this???
>
> When one gets a lot of replies one should probably thank for them, but in
> this case, there are few replies to thank for. It's okay to give
> constructive critisism, but very little of this critisism is constructive. I
>
> agree that my first posting should'be been clearer, but why don't someone
> just say that in a nice way instead of making such a big deal out of how
> stupid I am.
>
> Before I repost my question, I would like to say something to some of the
> people replying to my message:
>
> Abigail: What's your problem? Did you actually read my posting? The first
> line goes something like this: "I've just started learning Perl..." Did it
> ever occur to you that I either know what "-w" "use strict" or modules are
> nor do I know how to use them. I'm supposing that modules are some pre-made
> scripts since you say they are "made by people with a clue".(It's probably
> not!) Well, you obviously didn't read the rest of the the first sentence,
> cause it goes something like this: "...and I recently modified a CGI-script"
>
> And did it ever occour to you that I might want to "have a clue" myself
> someday? And the only way to leraning this, is by doing it myself !
> I'm eager to learn CGI-scripting - so what if I "don't have the appropriate
> environment to test my work with."? I want to learn it just the same, and I
> will too, you'll see. And that I didn't give you an error message. The only
> error message I can give is in the subject line, you see THAT'S THE PROBLEM.
>
> If I had an error msg, I would've worked out the problem myself.
>
> There - that's some constructive critisism for you. Try using it sometime,
> instead of telling people to crawl under a rock (are you sure that your
> daddy allows you to play with the computer?)
>
> Bart Lateur:
> Thanks for actually caring about helping a novice. The other posters have
> got a lot to learn from you !
>
> Okay, let's rewind this tape and start from the top.........<<............
>
> Hi!
>
> I have a problem with a CGI script which I altered. The script is a usual
> mil-the-form
> script which sends tha data of the form to someones (my) E-mail adress. I
> altered the script a little so that it would read the recipient and the
> subject-line from a two hidden-fields in the the form, and added the
> following line:
>
> $value =~ s/%40/@/;
>
> and I also changed the output HTML-code to suit my needs. But when I hit the
>
> submit-button I get a page in the web-browser with the following msg:
>
> Internal Server Error
>
> The server encountered an internal error or misconfiguration and was unable
> to complete your request.
>
> Please contact the server administrator, webmaster@bardblikk.no and inform
> them of the time the error occurred, and anything
> you might have done that may have caused the error.
>
> The form can be found at http://home.sol.no/~webpages/mailform.htm and a
> copy of the script in *.txt version can be located at
> http://home.sol.no/~webpages/mailform.txt
>
> I would appriciate any help you can give my !
>
> Regards
>
> Eirik Johansen
> A NEWBIE IN CGI AND PERL!!!
>
> Eirik Johansen wrote:
>
> > Hi !
> >
> > I've just started learning Perl and I recently modified a CGI-skripy,
> > but now it won't work and I don't know why. Would someone be as kind as
> > to rund it un their Unix shell (I don't have Unix) and tell me which
> > line makes the error.
> >
> > Thanks so very much !
> >
> > Regards
> >
> > Eirik Johansen
> >
> > #!/usr/bin/perl
> >
> > # This script will take information from a form
> > # and place it in a mail to the desired recipent
> >
> > print "Content-type:text/html\n\n";
> >
> > read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> > @pairs = split(/&/, $buffer);
> > foreach $pair (@pairs) {
> > ($name, $value) = split(/=/, $pair);
> > $value =~ tr/+/ /;
> > $value =~ tr/%40/@/;
> > $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> > $FORM{$name} = $value;
> > }
> >
> > $mailprog = '/usr/sbin/sendmail';
> >
> > # this opens an output stream and pipes it directly to the sendmail
> > # program. If sendmail can't be found, abort nicely by calling the
> > # dienice subroutine (see below)
> >
> > open (MAIL, "|$mailprog -t") or &dienice("Can't access $mailprog!\n");
> >
> > # here we're printing out the header info for the mail message. You must
> >
> > # specify who it's to, or it won't be delivered:
> >
> > print MAIL "To: $FORM{$recipient}\n";
> >
> > # In case the owner of the form has any questions, I'll set the
> > # reply-adress as my own
> >
> > $reply = 'webpages@email.com';
> >
> > print MAIL "Reply-to: $reply\n";
> >
> > # print out a subject line so you know it's from your form cgi.
> > # The two \n\n's end the header section of the message. Anything
> > # you print after this point will be part of the body of the mail.
> >
> > print MAIL "Subject: $FORM{$subject}\n\n";
> >
> > # here you're just printing out all the variables and values, just like
> > # before in the previous script, only the output is to the mail message
> > # rather than the followup HTML page.
> >
> > foreach $key (keys(%FORM)) {
> > print MAIL "$key = $FORM{$key}\n";
> > }
> >
> > # when you finish writing to the mail message, be sure to close the
> > # input stream so it actually gets mailed.
> >
> > close(MAIL);
> >
> > # now print something to the HTML page, usually thanking the person
> > # for filling out the form, and giving them a link back to your homepage
> >
> > print <<EndHTML;
> > <h2>Thank You</h2>
> > Thank you for writing. Your mail has been delivered.<p>
> > Do you want a form like this one? Then visit <a
> > href="http://webpages.findhere.com" target="_top">The Webpage of
> > Webpages</a>
> > </body></html>
> > EndHTML
> > ;
> >
> > sub dienice {
> > ($errmsg) = @_;
> > print "<h2>Error</h2>\n";
> > print "$errmsg<p>\n";
> > print "</body></html>\n";
> > exit;
> > }
------------------------------
Date: Fri, 08 Jan 1999 20:53:42 -0500
From: Eugene Sotirescu <eugene@snailgem.org>
To: Wayne <wayne@deerhurst.com>
Subject: Re: a couple of beginner questions here.
Message-Id: <3696B6A6.8A58A9BF@snailgem.org>
0. Have pity on us and post code instead of paragraph-long quizzes
;------------)
1. Have pity on yourself and use CGI.pm for your Perl CGI scripts (looks
like you're using the old cgi-lib.pl).
2. Have pity on Perl and distinguish btw hashes (associative arrays) and
arrays.
If your name/value pairs are in the %in hash, you can get at their values
with $in{'whatever_you_called_it'}, not whatever_you_called_it0 (this is
not correct in any case; if @in were an array you would have
$whatever_you_called_it[0], etc.).
3. If someone leaves one of the input fields blank, its value is going to
be an empty string. This enables you to check for it if you want your user
to input something:
&error_sub if $in{'email'} eq "";
4. I don't quite get your last question: each of your form elements has its
own name and can be picked out quite easily (see 2. above). You can do any
comparisons you want using these variables. Again, your problem here might
be that you don't understand arrays and hashes.
HTH
Wayne wrote:
> Just learning Perl and have 2 questions:
> 1. I am going to capture data from the web sent via a form with the post
> method. If I read data into %in I will get for eg.
> %in(name0, value0, name1, value1, name2, value2)
> If a visitor to my site doesn't fill in anything for value2 on the form
> will the array still have a name2 and will value2 just be zero? Or will
> array only have (name0, value0, name1, value1)?
>
> 2. A form contains Name and address information as well as a list of
> products and there price. A visitor will fill in a quantity beside a
> product and I want my perl program to calculate the total. I will be put
> the form data (sent via the post method) in an array %in. I was thinking
> of the approach where I have hidden fields in the form to match a
> product with the price. Now how would I get the program to match a
> product that has a quantity selected that is >=1 with it' price. I can't
> figure how to go through the array and pick out the quantity value(s)
> and not get the zipcode or even the strings.
>
> I hope this makes sense and I am probably overlooking something very
> basic here. Thanks for any advice to steer me in the right direction
>
> Sincerely,
> Wayne
------------------------------
Date: Sat, 09 Jan 1999 01:08:41 -0500
From: Wayne <wayne@deerhurst.com>
Subject: Beginner trying to figure out PERL for cgi use
Message-Id: <3696F269.BE239501@deerhurst.com>
A form asks for email address and it is put into %in.
My Perl script emails this address to someone. However what they see is:
istead of the @ sign in the address it is replace with a small box and
cirlce. Any ideas how I can avoid this? I do have this line in my code
for the email contents:
$header_buffer = "Content-Type: text/plain; charset=$char_set\r\n";
Also I have a scaler variable that contains a total eg .
$total =10.00
$total = $total + 10.00
Now when I send this to a web page to give a customer the total they
spend I would see
$10 and not $10.00 How do I force my script to keep 2 decimal places?
Thanks
Wayne
------------------------------
Date: Sat, 9 Jan 1999 00:50:46 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Convert textarea line wraps to print
Message-Id: <1dlc87z.1hwum2ic9cokwN@bay2-454.quincy.ziplink.net>
<shiloh@shell9.ba.best.com> wrote:
> Ronald J Kimball <rjk@linguist.dartmouth.edu> wrote:
> : not. But, as before, that's more of an HTML question. :-)
>
> I have seen these circular arguments so often I just
> had to post this.
How is that a circular argument?
Definition: Perl questions are questions which relate specifically to
the Perl programming language.
The poster's question did not relate specifically to the Perl
programming language; instead, it related to HTML, which can be output
by any programming language.
Therefore, the poster's question is not a Perl question.
By the way, you could have had more Perl content in your post if you had
written:
print <<EOT while 1;
> There's a hole in the bucket dear liza, dear Liza
> There's a hole in the bucket dear liza, a hole.
>
> Then patch it, dear Roger, dear Roger, dear Roger,
> Then patch it, dear Roger, dear Roger, patch it.
>
> [...]
>
> With a bucket, dear Roger, dear Roger, dear Roger,
> With a bucket, dear Roger, dear Roger, a bucket.
EOT
:-)
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Sat, 9 Jan 1999 00:50:49 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: determining controlling tty
Message-Id: <1dlc8e2.hbslffpzl1zzN@bay2-454.quincy.ziplink.net>
Craig Berbling <cberblin@us.dhl.com> wrote:
> I want to determine if my perl process is attached to a terminal or not.
> If not I will direct STDOUT to a log file, otherwise I will spew to the
> terminal. I don't want to rely on the output of the 'tty' command or any
> other external command. Is there an internal 'perl thingee' or method of
> determining this ?
>
> I have searched this news group and the moderated one, but my eyes are now
> tired so it's time to post.
Guess what, you forgot to search the documentation. :-)
perlfunc:
-X FILEHANDLE
-X EXPR
-X
A file test, where X is one of the letters listed below. This unary
operator takes one argument, either a filename or a filehandle, and
tests the associated file to see if something is true about it. If
the argument is omitted, tests $_, except for -t, which tests STDIN.
Unless otherwise documented, it returns 1 for TRUE and '' for FALSE,
or the undefined value if the file doesn't exist. Despite the funny
names, precedence is the same as any other named unary operator, and
the argument may be parenthesized like any other unary operator.
The operator may be any of:
[...]
-t Filehandle is opened to a tty.
perlfaq8:
How do I find out if I'm running interactively or not?
Good question. Sometimes C<-t STDIN> and C<-t STDOUT> can give
clues, sometimes not.
if (-t STDIN && -t STDOUT) {
print "Now what? ";
}
On POSIX systems, you can test whether your own process group
matches the current process group of your controlling terminal as
follows:
use POSIX qw/getpgrp tcgetpgrp/;
open(TTY, "/dev/tty") or die $!;
$tpgrp = tcgetpgrp(TTY);
$pgrp = getpgrp();
if ($tpgrp == $pgrp) {
print "foreground\n";
} else {
print "background\n";
}
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Fri, 08 Jan 1999 22:22:41 -0500
From: Eugene Sotirescu <eugene@snailgem.org>
Subject: Re: geting arguments
Message-Id: <3696CB81.BF0C6B81@snailgem.org>
http://stein.cshl.org/WWW/software/CGI/cgi_docs.html
tells you exactly how.
Matevz Sernc wrote:
> Hello
>
> I want that some user click on following link:
> http://www.domain.xyz/cgi-bin/here.cgi?user=mk10
>
> --
> How can i get the part after the "?" in a variable in here.cgi ??
>
> I then want to do an user-dependent output to the browser.
>
> But how to get the "mk10" in a variable ??
>
> Can anyone help me ? (maybe someone has an simple cgi, i can see at)
>
> Regards
>
> Matevz Sernc
------------------------------
Date: Fri, 8 Jan 1999 23:49:44 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: How do I find the path of the script calling me?
Message-Id: <olq677.sgr.ln@magna.metronet.com>
Khayu Nyein (khayu@shweinc.com) wrote:
: $ENV{'HTTP-REFERER'} is it, i think.
That is utter nonsense!
There was no mention of the Hypertext Transfer Protocol
anywhere in the specification of the problem...
Perl does not equal CGI!
Perl does not equal CGI!
Perl does not equal CGI!
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 9 Jan 1999 00:11:44 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: How to do an exact comparison?
Message-Id: <0vr677.ksr.ln@magna.metronet.com>
news.rogers.ca (luc2@travelpod.com) wrote:
: This may sound like a stupid question but I know if I do...
Yep.
: if ( $variable =~ /test/ )
: it will return true if "test" is in $variable but how do I format the if
: statement if I want it to return true only if the string in $variable is
: exactly "test" and not "mytest" or "test123"...
if ( $variable eq 'test' ) # regex is not for testing equality...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 09 Jan 1999 06:03:49 GMT
From: William Case <wcase@mediaone.net>
Subject: Memory Leak?
Message-Id: <3696F113.80CC6EE8@mediaone.net>
Hello everyone..
I have a small script [see code below] that runs on a web site hosted by
a local hosting co. Recently, they have been complaining that this
script is causing their server [An NT server, running perlis.dll] to
crash several times a day. They say that their resource monitor shows
CPU usage at 100% and this script as the culprit, just before everything
blows up..
This script basically takes a file the user is uploading, saves it to
the "ftp" directory, and then renames it based on a var passed to the
script. To me, it doesn't look very complicated, but obviously something
is awry.
Any help or suggestions for possible avenues of modification would be
greatly appreciated.
Sincerely,
William Case
-----------[Code - Begin]------------
#!/usr/local/bin/perl -Tw
require 5.001;
require "cgi-lib.pl";
MAIN:
{
my ($new_name, $path_name, $extension);
my (%cgi_data, # The form data
%cgi_cfn, # The uploaded file(s) client-provided name(s)
%cgi_ct, # The uploaded file(s) content-type(s). These are
# set by the user's browser and may be unreliable
%cgi_sfn, # The uploaded file(s) name(s) on the server (this
machine)
$ret, # Return value of the ReadParse call.
$buf # Buffer for data read from disk.
);
$cgi_lib::writefiles = "../ftp";
$cgi_lib::maxdata = 100000;
$ret = &ReadParse(\%cgi_data,\%cgi_cfn,\%cgi_ct,\%cgi_sfn);
$extension = substr( $cgi_cfn{'upfile'}, -3);
$new_name = $cgi_data{'name'} . ( $extension eq 'jpg' ? '.jpg' :
'.gif' );
$path_name = "../ftp/$new_name";
print &PrintHeader;
print &HtmlTop("File Upload Results");
print <<EOT;
<p>You have successfully uploaded your logo!.
<hr>
Click <a
HREF="../asp/logo_update.asp?id=$cgi_data{'id'}&name=$save">here</a>
to SAVE your logo.
<pre>
EOT
print "</pre>\n";
print &HtmlBot;
open( INFILE, "<$cgi_sfn{'upfile'}" );
open( OUTFILE, ">$new_name" );
binmode( INFILE ); binmode( OUTFILE ); # crucial for binary files!
while ( read( INFILE, $buffer, 1024 ) )
{
print OUTFILE $buffer;
}
close( INFILE ); close( OUTFILE );
unlink($cgi_sfn{'upfile'}) or &CgiDie("Unable to rename
files.\n","Reason: $!\n");
}
-----------[Code - End]-------------
------------------------------
Date: Fri, 8 Jan 1999 23:56:27 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: output to multiple places...
Message-Id: <b2r677.sgr.ln@magna.metronet.com>
perlstudent@my-dejanews.com wrote:
: but, say i have a log file being created e.g (system "ls -1 > log.txt")
: which i wanted to be ouput to the screen dynamically as it is being
: created......could some one help me out here?
open(LS, 'ls -1 |') || die 'could not fork';
open(LOG, '>log.txt') || die "could not open 'log.txt' $!";
while (<LS>) {
print;
print LOG;
}
close(LS);
close(LOG);
But no self respecting Perl programmer would shell out and use
'ls' for something that is so easy to do from within Perl
itself ( perldoc -f readdir )...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". 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". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 4600
**************************************