[16122] in Perl-Users-Digest
Perl-Users Digest, Issue: 3534 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 2 00:05:27 2000
Date: Sat, 1 Jul 2000 21:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <962510708-v9-i3534@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 1 Jul 2000 Volume: 9 Number: 3534
Today's topics:
Re: $$$$$ username <nospam@mynet.com>
Re: ***Do not use this code!*** Re: Perl Help Please! <danny@lennon.postino.com>
@mews gr8ful1@c237627-b.moline1.il.home.com
@MeWS gr8ful1@c237627-b.moline1.il.home.com
Re: @MeWS <care227@attglobal.net>
Re: [win98] apache, perl, php4, mysql <randy@theory.uwinnipeg.ca>
Re: Can get perl to open doc, but how do I get it to op (Tad McClellan)
Re: Can get perl to open doc, but how do I get it to op <star@sonic.net>
Can't get Blat working on NT server paul_work@yahoo.com
Re: Can't get Blat working on NT server <care227@attglobal.net>
Re: cross-module inclusion and use (Neil Kandalgaonkar)
Re: DBI: Error inserting into dbf file <bwalton@rochester.rr.com>
foreach and hashes (Andy Smith)
Re: foreach and hashes (Neil Kandalgaonkar)
Help with Net::NNTP <krobb7@NOhomeSPAM.com>
Re: how to get text enclosed by matching () ? (Tad McClellan)
Re: how to get text enclosed by matching () ? andre_sanchez@my-deja.com
Re: newbie with a big problem (Tad McClellan)
Re: newbie..kinda... I've got a BIG problem <care227@attglobal.net>
Numbers and Strings and... <joe_beanNOjoSPAM@coffeehome.com.invalid>
Re: Numbers and Strings and... (Craig Berry)
Re: Numbers and Strings and... (Tad McClellan)
Re: Perldoc and Windows98 <randy@theory.uwinnipeg.ca>
shell into Perl (The National Folk Hero of the Net)
Re: Spliting things (Tad McClellan)
Re: Use of uninitialized value <nospam@mynet.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 01 Jul 2000 23:07:51 GMT
From: HawaiiFiveO <nospam@mynet.com>
Subject: Re: $$$$$ username
Message-Id: <962456342.470956765@main>
On Wed, 28 Jun 2000, /$username/ wrote:
>How do you check for/parse special PERL characters like $,@,% from FORM
>fields on a POST.
>
>For example,
>if $_ = "a$b$c$d"
>and i do this..
> $_=~s/\x24/""/eg; #-- Tried "$" and variations instead of \x24
$_ =~ s/\$//g;
You can esacape those characters: \$\@\% to match them
Regards,
Ben
------------------------------
Date: 1 Jul 2000 22:28:25 GMT
From: <danny@lennon.postino.com>
Subject: Re: ***Do not use this code!*** Re: Perl Help Please!
Message-Id: <8jlra9$s54$3@lennon.postino.com>
User-Agent: tin/1.4.2-20000205 ("Possession") (UNIX) (Linux/2.2.14-5.0 (i586))
In comp.lang.perl.misc Paul Taylor <pap@notheresotonians.org.uk> wrote:
[snip]
> Two problems arisen, neither answered in a constructive manner.
> Perl is supposed to be a community. In a community, people contribute when
> they can, right or wrong. There are always going to be leaders in a community,
> and certain individuals are going to know a great deal more about the
> mechanisms of that community.
> However, when that is the case, such individuals should educate, not berate
> those in need of help. In this thread, you had every right to point out the
> security shortcomings in my script. You could have suggested an alternative,
> or added to the script provided in order to make it safe.
Hear, hear. I count 19 posts in this thread, lots of accusations and flames,
yet not a single example of how to use taint checking to safely open and
read a file. Sometimes read the FAQ just doesn't cut it, and this is one of
those times.
--
Danny Aldham Providing Certified Internetworking Solutions to Business
www.postino.com E-Mail, Web Servers, Web Databases, SQL PHP & Perl
------------------------------
Date: Sat, 01 Jul 2000 22:40:26 GMT
From: gr8ful1@c237627-b.moline1.il.home.com
Subject: @mews
Message-Id: <uru75.30284$dF.1183295@news1.rdc1.il.home.com>
aloha,
i had the strangest thing happen to me today, and i thought it
was something i could share with the rest of you, to see if anyone
could explain to me why this happened, or else just to let you in
on an unexplained perl phenomenon which occured to me today.
my script went something like this...
#!/usr/bin/perl
use Net::NNTP;
use MIME::Base64;
my @bin = ('alt.binaries.mpeg.mp3', 'alt.binaries.music.mp3', 'alt.binaries.sounds.mp3');
my @alt = ('alt.music.mp3', 'alt.no-advertising.files.audio.mp3');
my @seven =
(); # hit return key by accident in console mode
my @mews = glob("/egypt/GReeK/septuagint.mp3/*.mp3"); # this is where the crazy
# things started to happen...
print join(" ", @mews);
--
In the beginning God created the Heaven and the Internet.
Now the internet was unformed and void,
and darkness was upon the face of the circuitry.
And God said, 'Let there be Open Source.' And there was Open Source.
And God saw the Open Source, that it was good;
and God divided the Open Source from the commercial software...
------------------------------
Date: Sat, 01 Jul 2000 22:45:50 GMT
From: gr8ful1@c237627-b.moline1.il.home.com
Subject: @MeWS
Message-Id: <ywu75.30285$dF.1183348@news1.rdc1.il.home.com>
now, when i ran the script with the array named @mews...
nothing happened just a blank screen staring me back in the face..
but when i edited the file after a long time of trying to figure
"what in the world..??"
and called it instead @MeWS
and it worked.
can anyone explain to me this mystery?
--
GReeK music: http://c237627-b.moline1.il.home.com/GReeK/mp3.html
--
In the beginning God created the Heaven and the Internet.
Now the internet was unformed and void,
and darkness was upon the face of the circuitry.
And God said, 'Let there be Open Source.' And there was Open Source.
And God saw the Open Source, that it was good;
and God divided the Open Source from the commercial software...
------------------------------
Date: Sat, 01 Jul 2000 23:38:13 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: @MeWS
Message-Id: <395EB925.90A035C5@attglobal.net>
gr8ful1@c237627-b.moline1.il.home.com wrote:
>
> now, when i ran the script with the array named @mews...
> nothing happened just a blank screen staring me back in the face..
> but when i edited the file after a long time of trying to figure
> "what in the world..??"
> and called it instead @MeWS
> and it worked.
> can anyone explain to me this mystery?
What? The mystery of why you decided to make this question into 2
posts? I can't think of a single explanation.
> In the beginning God created the Heaven and the Internet.
> Now the internet was unformed and void,
> and darkness was upon the face of the circuitry.
> And God said, 'Let there be Open Source.' And there was Open Source.
> And God saw the Open Source, that it was good;
> and God divided the Open Source from the commercial software...
What a bunch of pop-culture babble. I guess "open source" is hip
and gnarly, huh? Dude.
------------------------------
Date: Sat, 1 Jul 2000 17:03:46 -0500
From: "Randy Kobes" <randy@theory.uwinnipeg.ca>
Subject: Re: [win98] apache, perl, php4, mysql
Message-Id: <8jlq0j$q6p$1@canopus.cc.umanitoba.ca>
Jon K. <cdr39750@par.odn.ne.jp> wrote in
message news:395DBF98.40ADCA9F@par.odn.ne.jp...
> Hi guys,
and gals ....
>
> I want to setup a development environment in my win98.
> Up till now, I have only managed to setup apache.
> I have problems in getting apache to recognize the perl scripts and php
> scripts.
> Btw, how do I install the DBI and the MySQL package for perl?
> Do I just unzip the same files used by perl for linux under
> perl\lib\site ?
For the perl-related aspects of your questions, see
ActiveState's site:
http://www.activestate.com/Products/ActivePerl/docs/index.html
This site also has some information about web
stuff, but it'd be better to consult the docs for
your web server and the docs for php to get
help on those topics.
best regards,
randy kobes
------------------------------
Date: Sat, 1 Jul 2000 22:46:46 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Can get perl to open doc, but how do I get it to open html on thefly?
Message-Id: <slrn8ltb8m.8u0.tadmc@magna.metronet.com>
[ Please put your comments *following* the quoted text that you
are commenting on.
Jeopardectomy performed.
]
On Sat, 01 Jul 2000 23:03:23 GMT, arthur <star@sonic.net> wrote:
>in article 395E40E9.E5AC3FDA@epotec.com, James Fisher at jfisher@epotec.com
>wrote on 7/1/00 11:06 AM:
>
>star@sonic.net
>> It looks to me that you have two options...
>>
>> 1. Open the file and write to the std output.
>> 2. Redirect the user to the file.
>>
>> JF
>>
>> arthur wrote:
>>
>>> Good Day,
>>>
>>> I have a script that can open and post to a file in my directory but how can
>>> I make that file (it is in html format) open on the web?
>>>
>Great thanks for the help! but I do not understand (ok I admit it, sometimes
>I am thick) could someone please give me a simple example of 1 & 2
'perldoc' is a program for looking up stuff in the standard
docs that you got along with perl.
Learn to use it:
perldoc perldoc
"Open the file"
perldoc -f open
"and write to the std output"
perldoc -f print
"Redirect the user to the file"
The Perl part of that question is also answered with
perldoc -f print
_What_ to output to cause the redirect is not a Perl question,
it is a CGI question. There is a newsgroup for CGI questions:
comp.infosystems.www.authoring.cgi
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 01 Jul 2000 23:03:23 GMT
From: arthur <star@sonic.net>
Subject: Re: Can get perl to open doc, but how do I get it to open html on thefly?
Message-Id: <B5831DC3.22FB%star@sonic.net>
in article 395E40E9.E5AC3FDA@epotec.com, James Fisher at jfisher@epotec.com
wrote on 7/1/00 11:06 AM:
Great thanks for the help! but I do not understand (ok I admit it, sometimes
I am thick) could someone please give me a simple example of 1 & 2
Thanks,
~arthur
star@sonic.net
> It looks to me that you have two options...
>
> 1. Open the file and write to the std output.
> 2. Redirect the user to the file.
>
> JF
>
> arthur wrote:
>
>> Good Day,
>>
>> I have a script that can open and post to a file in my directory but how can
>> I make that file (it is in html format) open on the web?
>>
>> #!/usr/bin/perl
>>
>> use CGI qw(:standard);
>> use IO File;
>>
>> print header;
>>
>> print start_html('A Simple Example'),
>> h1('A Simple Example'),
>> start_form,
>> "What's your question? ",textfield('$question'),
>> p,
>> "What's the answer? ",textfield('$answer'),
>> p,
>> submit,
>> end_form,
>> hr;
>>
>> if (param()) {
>> print
>> "Your question is: ",em(param('$question')),
>> p,
>> "The answer is: ",em(param('$answer')),
>> p,
>> open (HOPE, ">dat.html") || die print "cant open:";
>> print (HOPE "<html>\n<head>\n<title>this is the working
>> copy</title>\n<body>");
>>
>> print (HOPE (param('$question')));
>> print (HOPE "\n");
>> print (HOPE (param('$answer')));
>>
>> print (HOPE "\n</body>\n</html>");
>> close HOPE;
>> hr;
>> }
>> print end_html;
>>
>> Thanks,
>> ~arthur
>> star@sonic.net
>
------------------------------
Date: Sun, 02 Jul 2000 01:07:42 GMT
From: paul_work@yahoo.com
Subject: Can't get Blat working on NT server
Message-Id: <8jm4ko$snm$1@nnrp1.deja.com>
I have moved some sites from a Unix host to an NT one and I'm having
trouble (about 8 hours of trouble so far) getting Blat working.
I am using the following command line:
blat.exe e:/ctw/blattest.txt -s "sending blattest.txt" -t
"pab@cutey.com" -f pab@cutey.com
Where e:/ctw/blattest.txt is my little test file (path correct
according to my FTP program) which does exist [as far as I can tell].
The above line is called with the system() command. It fails.
I have uploaded my little test script at:
http://www.clocktowerweb.co.uk/mail.txt
And you can see it working here:
http://www.clocktowerweb.co.uk/cgi-bin/mail.pl
BTW, the Perl script I am using is based on this:
http://gepasi.dbs.aber.ac.uk/softw/blatpl.txt
which itself was found from the original Blat page:
http://gepasi.dbs.aber.ac.uk/softw/Blat.html
Would be extremely grateful for any pointers.
Many thanks
Paul, thinking that sendmail was much easier...
- --
* Paul Baker paul_work@yahoo.com *
* Maidenhead.net http://www.maidenhead.net/ *
* ClockTowerWeb Ltd http://www.clocktowerweb.co.uk/ *
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sat, 01 Jul 2000 23:35:17 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Can't get Blat working on NT server
Message-Id: <395EB875.AC9F5DCB@attglobal.net>
paul_work@yahoo.com wrote:
>
> I have moved some sites from a Unix host to an NT one and I'm having
> trouble (about 8 hours of trouble so far) getting Blat working.
Your post is way off topic. There is nothing remotely Perl
related here. Try a newsgroup more associated with the source
of your problem, specifically Blat.
------------------------------
Date: Sun, 02 Jul 2000 00:17:44 GMT
From: neil@brevity.org (Neil Kandalgaonkar)
Subject: Re: cross-module inclusion and use
Message-Id: <8jm1ar$hml$1@localhost.localdomain>
In article <395D6177.11B7D653@rochester.rr.com>,
Bob Walton <bwalton@rochester.rr.com> wrote:
>Steve Revilak wrote:
>>
>> $ perl -w A.pm
>> Subroutine a_sub redefined at A.pm line 9.
>> $ perl -w B.pm
>> Subroutine b_sub redefined at B.pm line 10.
>> $
>>
( Note: there already is a B module, so I changed your examples to
X.pm and Y.pm. )
Normally you would never run a module as a script like that. Perl
has a special hash %INC which keeps track of what you've 'use'd (require,
actually) and usually won't load a module twice.
When you do it like you're doing it, %INC won't work.
if you do
$ perl -we 'use X; use Y;'
like any normal module-using script, you see no warnings.
>Well, since things are OK at runtime, you might just turn warnings off
>and back on by adding
>
> no warnings;
> ...
> use warnings;
>
>around the sub's.
Assuming you still needed this, you would like to keep the benefits of
warnings without turning them all off.
If you have perl 5.6, you can use lexical warnings:
# file X.pm
package X;
use strict;
{
no warnings 'redefine'; # perldoc perllexwarn
use Y;
sub x_sub { print "foo" }
sub another_x_sub { print "boing" }
}
# etc...
But this seems a little silly.
BTW, some general comments on your modules:
> use lib ".";
use lib "." is not usually necessary.
$ perl -e 'print map { "$_\n" } @INC'
> printf("a_sub got " . @_ . "\n");
Odd mix of C and perl here. You really want:
print "a_sub got @_\n";
--
Neil Kandalgaonkar <neil@brevity.org>
------------------------------
Date: Sun, 02 Jul 2000 03:55:40 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: DBI: Error inserting into dbf file
Message-Id: <395EBD81.C48D8136@rochester.rr.com>
Kirill Sapelkin wrote:
>
> Hello !
>
> I am trying to load an xbase dbf file with data from a "|" delimited
> text file. I can insert specific values like ('joe','moe') but I cannot
> figure out how to load from a text file. I tried to imitate the example in DBI
> perldoc page to no avail. Below are my efforts so far.
>
> Grateful for any help or direction.
>
> Kirill
> ********code
> #!/usr/bin/perl
> # This formats, recodes and writes to a text file
> use DBI;
> $dbh = DBI->connect("DBI:XBase:/usr/src/sbt");
> $sth = $dbh->prepare("insert into ar-custo ( custno ) values ( \@fields[0] )");
> open(BOOKLIST, "fgcust.unl");
> while(<BOOKLIST>) {
> chop;
> @fields = split(/\|/);
> $sth->execute(@fields[0]);
> }
> $dbh->disconnect();
>
> *****************error messages
> Error Messages.
>
> DBD::XBase::db prepare failed: Unknown SQL command near ` @fields[0] )'
> at ./test.pl line 7.
>
> Can't call method "execute" on an undefined value at ./test.pl line 12,
> <BOOKLIST> chunk 1.
...
> Kirill Sapelkin
> znanie@best.com
Well, I don't know anything about XBase, and it was an XBase error you
got. It looks like XBase isn't happy with the @fields[0] literal string
it received as part of an SQL "insert into" command. This doesn't
surprise me, as SQL as implemented in the databases I do know about
wouldn't be too happy about that either. If the XBase DBD driver works
like the rest, you might replace @fields[0] with ? . Then it might
work. The ? should be a valid placeholder for any DBD driver. This
would probably be a better placeholder than whatever XBase would usually
use, as it should be portable to other DBD drivers.
If you want to be nice to your database and driver, you should include a
$sth->finish; after your while loop (and maybe nice to yourself, if you
later modify your program to do some more with the database). Probably
nice to close the BOOKLIST filehandle, too. And also, to be really nice
to yourself, add ' or die "Oops, $!\n"' to your open statement --
someday you'll regret it if you don't :-).
--
Bob Walton
------------------------------
Date: Sun, 02 Jul 2000 02:04:04 GMT
From: asmith@hsonline.net (Andy Smith)
Subject: foreach and hashes
Message-Id: <395ea196$0$1526$7bbe8f7d@news.hsonline.net>
Greetings:
I am having proplems with what should be a simple script. The script
should do a directory listing and then print file names that match
certain criteria (contain a certain subdtring) to a Web page.
My current problem is filling a hash with file names and keys. The
keys in the hash should be the first part of the file name minus the
substring and the extension. I think the problem lies in this snippet
of code:
foreach (@dirl)
{
if ($_ =~ /^(\w+)-HOWTO\.html$/)
{
%FileList = ("$1" => "$_",);
}
}
When the foreach loop is done, the only key/value pair left in the
hash is the last on. I have varified this by:
print sort keys(%FileList);
I am obviously missing something important here.
Thanks,
Andy
------------------------------
Date: Sun, 02 Jul 2000 02:45:00 GMT
From: neil@brevity.org (Neil Kandalgaonkar)
Subject: Re: foreach and hashes
Message-Id: <8jm9uu$hrl$1@localhost.localdomain>
In article <395ea196$0$1526$7bbe8f7d@news.hsonline.net>,
Andy Smith <asmith@hsonline.net> wrote:
> foreach (@dirl)
> {
> if ($_ =~ /^(\w+)-HOWTO\.html$/)
> {
> %FileList = ("$1" => "$_",);
> }
> }
>
>When the foreach loop is done, the only key/value pair left in the
>hash is the last on.
$FileList{$1} = $_; # assign one element of a hash
%FileList = ( $1 => $_ ); # assign the entire hash from a list
--
Neil Kandalgaonkar <neil@brevity.org>
------------------------------
Date: Sun, 02 Jul 2000 00:50:35 GMT
From: Ken <krobb7@NOhomeSPAM.com>
Subject: Help with Net::NNTP
Message-Id: <395E9200.58290B39@NOhomeSPAM.com>
Hello,
$server = Net::NNTP->new("news");
($narticles, $first, $last, $name) = $server->group("misc.test");
$since = $server->date - (60*60*24*7);
foreach (@{$server->newnews($since)}) {
# etc.
}
newnews ( SINCE [, GROUPS [, DISTRIBUTIONS ]])
`SINCE' is a time value. `GROUPS' is either a group pattern
or a reference to a list of group patterns. `DISTRIBUTIONS'
is either a distribution pattern or a reference to a list of
distribution patterns.
Returns a reference to a list which contains the message-ids
of all news posted after `SINCE', that are in a groups which
matched `GROUPS' and a distribution which matches `DISTRIBUTIONS'.
$server->newnews($since) returns an undefined value. What format is the
time supposed to be in? Seconds since 1970? I can't seem to figure it
out.
Thanks,
Ken
------------------------------
Date: Sat, 1 Jul 2000 17:42:50 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: how to get text enclosed by matching () ?
Message-Id: <slrn8lspeq.8i7.tadmc@magna.metronet.com>
On Sat, 01 Jul 2000 21:30:24 +0200, Christian Vandsų <christian@fabel.dk> wrote:
>On Sat, 1 Jul 2000 21:08:57 +0200, RonR <ronr@my-deja.com> wrote:
>
>
>>a line: "blabla bla (xyz, abc(n), xyz, abc(n)) etc etc"
>>I want to get the list enclosed by the matching braces
^^^^^^^^
^^^^^^^^
>>giving: "( xyz, abc(n), xyz, abc(n) )" or eventually without the braces.
>
>Using that .* is greedy:
>
>#! /usr/local/bin/perl -w
>
>use strict;
>my $line="blabla bla (xyz, abc(n), xyz, abc(n)) etc etc";
my $line="blabla bla (xyz, abc(n), xyz, abc(n)) etc) etc";
^
^ Oops!
my $line="blabla bla (xyz, abc(n), xyz, abc(n)) etc(X)etc";
^^^
^^^ Oops again!
>my $res = $1 if ($line=~ m/.*?(\(.*\))/g);
>
>print "Original line: $line\n Largest section in braces: $res\n";
That code only works "sometimes".
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 01 Jul 2000 23:57:17 GMT
From: andre_sanchez@my-deja.com
Subject: Re: how to get text enclosed by matching () ?
Message-Id: <8jm0go$q5i$1@nnrp1.deja.com>
In article <01HW.B5840E6900263FA41267D8B0@news.planet.nl>,
ronr@my-deja.com wrote:
> Hi,
>
> a line: "blabla bla (xyz, abc(n), xyz, abc(n)) etc etc"
> I want to get the list enclosed by the matching braces
> giving: "( xyz, abc(n), xyz, abc(n) )" or eventually without the
braces.
>
> Is there an easy way to do this ? The braces are always in pairs (if
that
This works:
$line = 'blabla bla (xyz, abc(n), xyz, abc(n)) etc etc';
$braces = '(' . $line . ')';
--
Their's not to make reply,
Their's not to reason why,
Their's but to do or die: -- Tennyson
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sat, 1 Jul 2000 17:55:42 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: newbie with a big problem
Message-Id: <slrn8lsq6u.8i7.tadmc@magna.metronet.com>
[ Please don't post the same things multiple times. Now you
have to search multiple places to find the answers. Folks
who see one thread might miss the other one.
It creates a big CF. ("C" stands for "cluster", "F" has
the usual interpretation.
)
Thanks.
]
On 01 Jul 2000 21:21:52 GMT, KCMage <kcmage@aol.com> wrote:
>Hi, I'm KC..and I'm kind of new to CGIs, so be gentle =)
OK, but you should realize that many (most) people here do
not use Perl in a CGI environment.
You may have better luck in a newsgroup that is associated
with the CGI environment (this is not such a newsgroup)
such as:
comp.infosystems.www.authoring.cgi
>In any case, I was commissioned by my manager to write a CGI
^^^^^^^^^^^
You cannot do that.
The Common Gateway Interface (CGI) has already been written
by some standards committee or other.
You _can_, however, write a CGI _program_ that follows that
interface spec.
>My main concern is the fact that the
>CGI refuses to run from a browser standpoint. It keeps giving me an "Internal
>Server Error" of 500
perldoc -q 500
"My CGI script runs from the command line but not the
browser. (500 Server Error)"
You are expected to check the Perl FAQ *before* posting to the
Perl newsgroup.
So, you might also want to try
perldoc -q CGI
"How can I make my CGI script more efficient?"
"Where can I learn about CGI or Web programming in Perl?"
"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?"
In addition to the Server Error one.
>#!/usr/bin/perl
#!/usr/bin/perl -wT
use strict;
1) enable warnings
2) enable taint checking
3) be strict about variables (and other stuff)
>read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>@pairs = split(/&/, $buffer);
>foreach $pair (@pair) {
>($name, $value) = split(/=/, $pair);
>$value =~ tr/+/ /;
>$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>$value =~ /s\n/ /g;
>$value =~ /s\r//g;
>$value =~ /s\cM//g;
>$FORM{$name} = $value;
>}
You can replace all of that with 2 lines if one of the lines is:
use CGI;
perldoc CGI
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 01 Jul 2000 23:31:20 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: newbie..kinda... I've got a BIG problem
Message-Id: <395EB788.DB142C55@attglobal.net>
KCMage wrote:
>
> Hi, I'm KC..and I'm kind of new to CGIs, so be gentle =)
Hi, I'm Drew, and the rest of this message is pretty much off topic
for this group. A better place would be a CGI newsgroup, such as
comp.infosystems.www.authoring.cgi
> MY main concern is the fact that the
> CGI refuses to run from a browser standpoint. It keeps giving me an "Internal
> Server Error" of 500, which means the script isn't running right.
And besides being off topic, its an FAQ for CGI programming with
<insert language name here>
> #!/usr/bin/perl
No use of -w or -T or 'use strict;'. Bad.
>
> #check the mail
> if ($FORM{'Email'}) {
> unless ($FORM{'Email'} =~ /\w+@\w+.\w+/) {
> print "Content-type: text/html\n\n";
The above is the only time you output a header. If you would have read
the FAQ you would see this as a problem.
> }
> }
The code below is cargo cult programming. The prefered method is to use
a module from the CGI family to get the form data. Check CGI.pm and
friends.
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> @pairs = split(/&/, $buffer);
> foreach $pair (@pair) {
> ($name, $value) = split(/=/, $pair);
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> $value =~ /s\n/ /g;
> $value =~ /s\r//g;
> $value =~ /s\cM//g;
> $FORM{$name} = $value;
> }
Here's a problem...
> #switches
> foreach $key (keys %boxes) {
> if ($FORM{$key} == 1) {
> print "$key\n"; # <-- a print ""; hmmmm
> }
> }
And again...
>
> #switches
> foreach $key (keys %boxes) {
> if ($FORM{$key} == 1) {
> print "$key\n";
> }
> }
Why was the above bit of code repeated? Why not make it a subroutine
if it really needs to be used a few times? And why are you printing
output before you've sent the header? Please read any CGI faq.
> close(MAIL) <-- forgot a semicolon or bad paste?
If indeed the semicolon was omited, you would never had compiled.
Using -w would have warned you about this. If its a bad paste, then
the lack of a valid header is certainly the cause of the problem.
HTH
------------------------------
Date: Sat, 01 Jul 2000 17:12:15 -0700
From: bean <joe_beanNOjoSPAM@coffeehome.com.invalid>
Subject: Numbers and Strings and...
Message-Id: <055bfdc8.159228e9@usw-ex0103-019.remarq.com>
I'm kind of new to Perl, and though I'm using it to write a CGI
script, I don't think that my question is specific to CGI
scripts, which is why I'm posting my question here.
Basically what I'm doing is generating two random characters,
and concatenating them using the following bit of code:
my @abcs = (a..z, A..Z);
srand;
$random_uin = $abcs[rand($#abcs)] . $abcs[rand($#abcs)];
Next, I wanted to check to see if those two characters existed
in a line of a text file I created. Each line of the text file
contains only one thing - two random characters. I read the text
file into an array using the following code:
open (onlinefile, "users_online.txt");
@users_online=<onlinefile>;
close (onlinefile);
My problem lies in trying to compare the two character strings I
have in the array and the two character string I randomly
generated. Using a basic "if X eq Y" statement, I tried to see
if the two pieces of information were the same. I got some funny
errors, and upon further investigation, using this code:
$new_line = $users_online[0] . $random_uin;
I found that though Perl was treating what had been read out of
the text file as a character string, it seemed to be treating
the randomly generated character string almost like a number.
When I print out $new_line, I get the value of $users_online,
then a new line, and the value of $random_uin.
I confirmed this (at least, I think I did) by dividing
$random_uin by 2, which give a value of 0. When I did this, Perl
printed the value of $users_online and 0 on the same line,
showing that it had successfully concatenated the two pieces of
information.
I guess my question is, how do I make Perl realize that my
randomly generated string is in fact a string of characters, and
not some sort of number? Or is this even what's happening?
Perhaps the best question I can ask is where can I find
information on how to fix this problem, or is there a better way
of generating the random string that eliminates this problem?
-----------------------------------------------------------
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: Sun, 02 Jul 2000 03:10:04 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Numbers and Strings and...
Message-Id: <sltckcgdop3117@corp.supernews.com>
bean (joe_beanNOjoSPAM@coffeehome.com.invalid) wrote:
: I'm kind of new to Perl, and though I'm using it to write a CGI
: script, I don't think that my question is specific to CGI
: scripts, which is why I'm posting my question here.
Congratulations; despite being 'kind of new', you've already made a
crucial distinction that eludes certain people for years.
: Basically what I'm doing is generating two random characters,
: and concatenating them using the following bit of code:
:
: my @abcs = (a..z, A..Z);
Barewords like that aren't a good idea; if you use -w, Perl will tell you
this. Better would be:
my @abcs = ('a'..'z', 'A'..'Z');
: srand;
No need to do that in modern versions of perl; see the doc on rand and
srand.
: $random_uin = $abcs[rand($#abcs)] . $abcs[rand($#abcs)];
rand() returns a floating-point number in the half-open interval [0..arg).
That is, it will always return something less than but *not* equal to its
argument. Since $#foo returns the index of the last element of @foo, and
arrays are 0-based, your construct will never pick the last element of
your array ('Z'). Use @foo in a scalar context to get the count of
elements in the array, which will behave correctly:
$random_uin = $abcs[rand @abcs] . $abcs[rand @abcs];
: Next, I wanted to check to see if those two characters existed
: in a line of a text file I created. Each line of the text file
: contains only one thing - two random characters. I read the text
: file into an array using the following code:
:
: open (onlinefile, "users_online.txt");
Always always *always* check the results of your open! This will save you
hours of wasted debugging time, I promise. Also, I find it useful to use
non-interpolating single quotes on constant strings, just so it's obvious
that they are constant when you're reading the code. And further, by long
convention filehandles are named in all caps; following this style will
make others' code more readable to you, and vice versa. So:
open ONLINEFILE, 'users_online.txt' or die $!;
[snip]
: My problem lies in trying to compare the two character strings I
: have in the array and the two character string I randomly
: generated. Using a basic "if X eq Y" statement, I tried to see
: if the two pieces of information were the same. I got some funny
: errors, and upon further investigation, using this code:
:
: $new_line = $users_online[0] . $random_uin;
:
: I found that though Perl was treating what had been read out of
: the text file as a character string, it seemed to be treating
: the randomly generated character string almost like a number.
: When I print out $new_line, I get the value of $users_online,
: then a new line, and the value of $random_uin.
I'm not sure what you mean by 'like a number'. Each element in
@users_online will indeed end with a newline (\n). Your statement above
takes the first line from the file and concatenates your
randomly-generated two-character string to it. Naturally, a newline ends
up in the middle of the resulting string.
If you want to dispose of all the newlines, you can do
chomp @users_online;
: I confirmed this (at least, I think I did) by dividing
: $random_uin by 2, which give a value of 0. When I did this, Perl
: printed the value of $users_online and 0 on the same line,
: showing that it had successfully concatenated the two pieces of
: information.
If you try to do math on a string, Perl tries to interpret the string as a
number. Since you can't interpret a two-letter string as a number, it
defaults to treating it as 0, which divided by 2 is still 0.
This shouldn't have changed the fact that the newline was still there on
the line read from the file. Show us the code that behaves otherwise,
please.
: I guess my question is, how do I make Perl realize that my
: randomly generated string is in fact a string of characters, and
: not some sort of number? Or is this even what's happening?
I doubt it is. :)
--
| Craig Berry - http://www.cinenet.net/users/cberry/home.html
--*-- "Beauty and strength, leaping laughter and delicious
| languor, force and fire, are of us." - Liber AL II:20
------------------------------
Date: Sat, 1 Jul 2000 22:40:26 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Numbers and Strings and...
Message-Id: <slrn8ltasq.8u0.tadmc@magna.metronet.com>
On Sat, 01 Jul 2000 17:12:15 -0700, bean <joe_beanNOjoSPAM@coffeehome.com.invalid> wrote:
>Next, I wanted to check to see if those two characters existed
>in a line of a text file I created. Each line of the text file
>contains only one thing - two random characters. I read the text
>file into an array using the following code:
>
>open (onlinefile, "users_online.txt");
>@users_online=<onlinefile>;
>close (onlinefile);
>
>My problem lies in trying to compare the two character strings I
>have in the array
You do not have two character strings in the array!
see for yourself:
foreach (@users_online) {
print length, "\n";
}
If you have two characters on a "line" in the file, as you
described above, then each line is 3 characters long
(there's a newline in there).
chomp(@users_online = <ONLINE_FILE>); # read lines and remove newlines
( I cannot bring myself to use all lower case filehandles, you
shouldn't use them either...
)
>and the two character string I randomly
>generated. Using a basic "if X eq Y" statement, I tried to see
>if the two pieces of information were the same.
A two character string can never equal a three character string.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 1 Jul 2000 17:43:19 -0500
From: "Randy Kobes" <randy@theory.uwinnipeg.ca>
Subject: Re: Perldoc and Windows98
Message-Id: <8jlsap$r7n$1@canopus.cc.umanitoba.ca>
Samay <samay1NOsaSPAM@hotmail.com.invalid> wrote in
message news:01552fc0.69c4cb43@usw-ex0104-033.remarq.com...
> Hi, I have installed ActiveState Perl on my windows98 machine.
> whenever I type 'Perldoc something' on command line it freezes.
> If something is indeed a word identified by perldoc, this
> problem doesn't show up..
I don't have this problem on Win98 - if I type
'perldoc garblefish', it reports back that no
documentation was found for "garblefish".
When you say it freezes, does that mean
you must reboot, or will Control-C work at
stopping it searching? Perhaps you have
a slower system, and it just takes a long time ...
best regards,
randy kobes
------------------------------
Date: 1 Jul 2000 22:26:49 -0400
From: colonel@monmouth.com (The National Folk Hero of the Net)
Subject: shell into Perl
Message-Id: <8jm999$51e$1@shell.monmouth.com>
I recently posted this to comp.lang.perl.modules by mistake:
According to the man page PERLRUN(1), a good way to run a Perl script
without a working autoexec line is:
eval 'exec /usr/bin/perl $0 ${1+"$@"}'
if $running_under_some_shell;
I've been using this, which is shorter:
"false" || eval 'exec /usr/bin/perl $0 ${1+"$@"}';
It works fine for ksh, which is all I ever run it with.
Are there any common shells for which it will not work?
-:-
"To what do I owe the honor of this unexpected visit, Lord
Ruthven ... alias Lyford Pemberton!"
H. C. Artmann, "Tom Parker, International Detective"
--
Col. G. L. Sicherman
home: colonel@mail.monmouth.com
work: sicherman@lucent.com
web: <http://www.monmouth.com/~colonel/>
--
Col. G. L. Sicherman
home: colonel@mail.monmouth.com
work: sicherman@lucent.com
web: <http://www.monmouth.com/~colonel/>
------------------------------
Date: Sat, 1 Jul 2000 17:37:51 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Spliting things
Message-Id: <slrn8lsp5f.8i7.tadmc@magna.metronet.com>
On Sat, 01 Jul 2000 10:27:54 -0700, psycho <psychoNOpsSPAM@pcpatches.com.invalid> wrote:
>hey, tad..
^^^
Please post to the newsgroup when you are addressing the newsgroup.
Use email for private communication.
(_I_ don't generally answer such email messages though,
that is what my clients pay for.
)
>i've got a probelm still, take a look
>
>http://www.pcpatches.com/cgi-bin/cgimania/test/testing.cgi
You are right.
You still have a problem.
Your point?
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 01 Jul 2000 23:14:48 GMT
From: HawaiiFiveO <nospam@mynet.com>
Subject: Re: Use of uninitialized value
Message-Id: <962456759.345654455@main>
>Heh. actually, I do have the line
>
> my($TmpImages)="../../../../tmpimages";
>
hmmmm try coding the entire path ...
Ben
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 3534
**************************************