[24202] in Perl-Users-Digest
Perl-Users Digest, Issue: 6394 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 13 09:06:10 2004
Date: Tue, 13 Apr 2004 06:05:13 -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 Tue, 13 Apr 2004 Volume: 10 Number: 6394
Today's topics:
cgi charset problem (Bijoy)
Re: cgi charset problem <jurgenex@hotmail.com>
Re: cgi charset problem <me@privacy.net>
Check if opened process is still running <webmaster@hennevl.de>
Re: Check if opened process is still running (Anno Siegel)
Re: Check if opened process is still running <webmaster@hennevl.de>
Curses::UI <keithABUSE@araneid.com>
Re: Design choice: subclassing or "supplementing" (Anno Siegel)
Re: download my bbs... <tore@aursand.no>
Re: download my bbs... <flavell@ph.gla.ac.uk>
if someone can give me an example of RowCount method of <loyata@tom.com>
Re: import() override - comments? (Anno Siegel)
Re: Initializing an anonymous hash (repost) (Neil Shadrach)
Re: MS Access Date/Time Data type mismatch <s.patterson@freeuk.com>
Re: Multiple replaces (Anno Siegel)
Re: Multiple replaces <nobull@mail.com>
Re: Need help with Parsing HTML <gisle@activestate.com>
need to find word, and comment out next 5 lines (joe shaboo)
Re: new bbs <nospam_007@yahoo.com>
Re: PERL web addressing <spamtrap@dot-app.org>
Re: Question about Perl and Expect (Markus Kemp)
Re: SOAP:Lite Client - server message passing <mail@mail.com>
Re: striped name to variable (GreenLight)
Re: system or exec <me@privacy.net>
Re: the code for bbs 3 <tore@aursand.no>
Re: WebExplorer as Perl-CGI <me@privacy.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 13 Apr 2004 01:07:56 -0700
From: vbijoy@yahoo.com (Bijoy)
Subject: cgi charset problem
Message-Id: <3fbde14a.0404130007.2b1b8c24@posting.google.com>
Hi
I had passed the <meta Http_Equiv="Content-Type"
Content="text/html; charset=windows-1256"> to browser Internet
Explorer from a cgi script. But the browser doesn't act with Arabic
Encoding. At the same time if I save the source in html format, it
will work fine.
Thanks in advance for your help.
Bijoy
------------------------------
Date: Tue, 13 Apr 2004 08:13:28 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: cgi charset problem
Message-Id: <IiNec.23227$F9.1071@nwrddc01.gnilink.net>
Bijoy wrote:
> I had passed the <meta Http_Equiv="Content-Type"
> Content="text/html; charset=windows-1256"> to browser Internet
> Explorer from a cgi script. But the browser doesn't act with Arabic
> Encoding. At the same time if I save the source in html format, it
> will work fine.
Do you have a Perl problem, too?
jue
------------------------------
Date: Tue, 13 Apr 2004 22:17:48 +1200
From: "Tintin" <me@privacy.net>
Subject: Re: cgi charset problem
Message-Id: <c5geo3$1bei8$1@ID-172104.news.uni-berlin.de>
"Bijoy" <vbijoy@yahoo.com> wrote in message
news:3fbde14a.0404130007.2b1b8c24@posting.google.com...
> Hi
> I had passed the <meta Http_Equiv="Content-Type"
> Content="text/html; charset=windows-1256"> to browser Internet
> Explorer from a cgi script. But the browser doesn't act with Arabic
> Encoding. At the same time if I save the source in html format, it
> will work fine.
> Thanks in advance for your help.
You need to output the appropriate header, eg:
use CGI;
my $q = new CGI;
print $q->header(-charset=>'windows-1256');
------------------------------
Date: Tue, 13 Apr 2004 10:39:04 +0000
From: Hendrik vom Lehn <webmaster@hennevl.de>
Subject: Check if opened process is still running
Message-Id: <c5g8tq$7qj$06$1@news.t-online.com>
Hi,
I have opened a process with open FH, "|myproc";
My program is running in an infinite while loop and shall exit if the opened
process has been closed. How can I check this?
Thanks a lot
Hendrik vom Lehn
------------------------------
Date: 13 Apr 2004 09:15:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Check if opened process is still running
Message-Id: <c5gb3m$kag$1@mamenchi.zrz.TU-Berlin.DE>
Hendrik vom Lehn <webmaster@hennevl.de> wrote in comp.lang.perl.misc:
> Hi,
>
> I have opened a process with open FH, "|myproc";
> My program is running in an infinite while loop and shall exit if the opened
> process has been closed. How can I check this?
$SIG{ CHLD} = sub { die "kid finished" };
For %SIG, see "perldoc perlvar". For general concepts, "perldoc
perlipc".
Anno
------------------------------
Date: Tue, 13 Apr 2004 11:39:32 +0000
From: Hendrik vom Lehn <webmaster@hennevl.de>
Subject: Re: Check if opened process is still running
Message-Id: <c5gcf5$asl$06$2@news.t-online.com>
Anno Siegel wrote:
> $SIG{ CHLD} = sub { die "kid finished" };
This works for me.
Thanks,
Hendrik
------------------------------
Date: Tue, 13 Apr 2004 20:20:10 +1000
From: Keith Davies <keithABUSE@araneid.com>
Subject: Curses::UI
Message-Id: <874qro9o2t.fsf@arthur.zarquon>
I'm not sure what I'm doing wrong:
#!/usr/bin/perl -w
use strict ;
use Curses::UI;
my $cui = new Curses::UI;
my %w;
$w{1} = $cui->add(
'w1', 'Window',
-border => 1,
-y => 1,
-padbottom => 3,
);
my %notes = ('lblNotes', 'Label',
-text => 'Notes: ',
-x => 1,
);
$w{1}->add(%notes);
$cui->mainloop();
This results in the following error:
Fatal program error:
------------------------------------------------------------------------
Could not load Curses::UI::Notes: from Curses/UI/Notes.pl:
Can't locate....
Ultimately I want the %notes hash to live in another hash to give a
hash of hashes. Can someone tell me what I'm doing wrong.
------------------------------
Date: 13 Apr 2004 08:37:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Design choice: subclassing or "supplementing"
Message-Id: <c5g8ss$ipo$3@mamenchi.zrz.TU-Berlin.DE>
Abigail <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMDCCCLXXIV
> September MCMXCIII in <URL:news:c575e7$q5$1@mamenchi.zrz.TU-Berlin.DE>:
> && J Krugman <jkrugman@yahbitoo.com> wrote in comp.lang.perl.misc:
> && >
> && >
> && >
> && >
> && > I have this class from CPAN (let's call it, creatively enough, Foo)
> && > that suits me fine in almost every respect, except for one workhorse
> && > method (say, bar) that I think could be significantly enhanced.
> && > One possibility would be to create a subclass MyFoo of Foo just
> && > for the purpose of overriding bar.
> &&
> && Overriding base class methods is more than just replacement. If
> && the base class uses the overridden method internally, it will call
> && the *overriding* method on objects from your (inheriting) class.
> && This is what allows old code to call new code in OO, and it is at the
> && heart of inheritance.
>
> I don't get your point here. If you replace the method, old code will
> call new code as well. The difference is when the base class calls
> the method in the non-OO way - then with overriding the original code
> will be called, with replacing, the new code.
I was contrasting inheritance with importation. "...replacement of
*imported* routines" is what I should have said.
If you import some routines from a module Foo and replace others with
your own, your new code will never be called by the imported routines.
You have to invade Foo and make changes there to get that.
If you inherit from a class Foo and override some methods, Foo can
call you back on your overriding methods.
I was trying to point out that with OO you can have your cake (stay out
of foreign name spaces) and eat it too (have old code call your new
code).
Side note: Inheritance takes you only so far: the "old code" must be
OO to call new code, so it cannot be too old. Operator overloading
opens the door still wider and can make any old code call new code.
Anno
------------------------------
Date: Tue, 13 Apr 2004 12:39:43 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: download my bbs...
Message-Id: <pan.2004.04.13.10.18.46.161378@aursand.no>
On Mon, 12 Apr 2004 23:38:46 -0700, Robin wrote:
> The free source bbs which, is definetly a little more secure is located
> at www.infusedlight.net/bbs/index.shtml
> Includes a really cool admin script and a cool header and footer.
Could you please include this additional information about your script?
* It's insecure.
* It's a good example on how _not_ to program.
* It's created by a non-programmer who shows no particular interest
in learning how to program.
This is useful information for anyone who's interested in using your
scripts. I guess it'll make them think twice.
--
Tore Aursand <tore@aursand.no>
"A teacher is never a giver of truth - he is a guide, a pointer to the
truth that each student must find for himself. A good teacher is
merely a catalyst." -- Bruce Lee
------------------------------
Date: Tue, 13 Apr 2004 12:43:34 +0100
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: download my bbs...
Message-Id: <Pine.LNX.4.53.0404131242040.16221@ppepc56.ph.gla.ac.uk>
On Tue, 13 Apr 2004, Tore Aursand wrote:
> > Includes a really cool admin script and a cool header and footer.
>
> Could you please include this additional information about your script?
>
> * It's insecure.
> * It's a good example on how _not_ to program.
[...]
Don't you think that the use of the word "cool", even once, would
have been enough to warn any serious users off?
------------------------------
Date: Tue, 13 Apr 2004 18:44:52 +0800
From: "Wang Qi" <loyata@tom.com>
Subject: if someone can give me an example of RowCount method of Win32::odbc
Message-Id: <c5ggbh$1i64$1@mail.cn99.com>
i want use this method to get the row count of a table named "SNP" from a
sql server database with the odbc DSN "control" and user "loyata" passwd
"asdf". From the cpan I cannot find the example of this method, so please
help me if you have used it.
------------------------------
Date: 13 Apr 2004 10:10:38 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: import() override - comments?
Message-Id: <c5geau$ngd$1@mamenchi.zrz.TU-Berlin.DE>
Matthew Braid <mb@uq.net.au.invalid> wrote in comp.lang.perl.misc:
> Hi all,
>
> I've got a slightly complex system of packages. There are two that are library
> packages, and a whole bunch that can be require'd as necessary to override some
> or all the functions in the library packages. This is not OO - its all
> functional.
>
> An overrider package looks like the following:
>
> package Override; # Fake name
> use strict;
> BEGIN {
> require Functions; # One of the library packages
> my $old_x = \&Functions::x;
> sub x {
> print "OVERRIDE!\n";
> $old_x->(@_);
This may be a place for "goto &$old_x". You'd avoid building up a new
stack frame for each override, and the caller remains the same.
> }
> *Functions::x = \&x;
> }
> 1;
> __END__
>
> This system means that many overrides can be made in succession and
> build on top
> of one another, which is what I want.
>
> However, it also means that use'ing a library package like:
>
> use Functions qw/x/;
>
> can be problematic and often loses overrides. At first I fixed this by using:
I don't see how. "use" loads the file only once. Since overriding
changes what &Functions::x points to, standard exportation should export
the overridden version of "x".
> require Functions;
> sub x { goto &Functions::x }
...nor do I see how this would help. Maybe you are doing something I'm
not expecting.
One problem I see is that the result of overriding may depend on the
sequence in which (the same) overriding actions happen. This is not
good, but I don't see how it can be avoided with this kind of subroutine
chaining.
{modified Exporter snipped]
Anno
------------------------------
Date: 13 Apr 2004 02:53:41 -0700
From: neil.shadrach@corryn.com (Neil Shadrach)
Subject: Re: Initializing an anonymous hash (repost)
Message-Id: <2d184bb4.0404130153.28359fd3@posting.google.com>
ctcgag@hotmail.com wrote in message
> warn "Ugly, but works";
You're being too modest.
> @{$a[@a]}{@k}=@v;
If I rework my original problem to be a little closer to your solution
:)
I wanted to eliminate %h from
@h{@k}=@v; $a[@a]=\%h;
I can just about convince myself that I understand if I allow the
pseudo-step of dereferencing both sides of the second statement as
arrays and then substitute in the first
@{$a[@a]}=@h; # ok I know I couldn't actually use @h like that - I did
say 'just about'
I'm not going to offer to stand up and jsutify that at a perl
conference though.
Thanks for that ( and thanks to the others who replied too )
------------------------------
Date: Tue, 13 Apr 2004 11:06:46 +0100
From: Stephen Patterson <s.patterson@freeuk.com>
Subject: Re: MS Access Date/Time Data type mismatch
Message-Id: <c5gej2$1afep$1@ID-157462.news.uni-berlin.de>
Jacquo Johnson wrote:
> The [Import Date] is defined as an MS Date/Time type and contains the
> following Db entry format: 4/12/2004 9:22:37 AM
>
> I've tried numerous literal values within the SELECT/WHERE but I am
> having absolutely no luck with other formats as well as locating a
> solution via the web.
It might be worth trying the ISO standard database date-time format
YYYY-MM-DD HH:MM:SS.000 in case the date you see in access is just
display formatting applied over a more standard date format.
--
Stephen Patterson http://patter.mine.nu/
steveSPAM@.patter.mine.nu remove SPAM to reply
Linux Counter No: 142831 GPG Public key: 252B8B37
Caution: breathing may be hazardous to your health.
------------------------------
Date: 13 Apr 2004 09:47:42 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Multiple replaces
Message-Id: <c5gcvu$mb4$1@mamenchi.zrz.TU-Berlin.DE>
Motti <kzin@myrealbox.com> wrote in comp.lang.perl.misc:
> I need to do multiple replaces in some files. For example say I need
> to change every 'die' to 'croak' and every 'warn' to 'carp' in all .pl
> files.
I must ask here, what kind of program maintenance is this? You're
changing every occurrence of "die" to "croak", in strings, comments,
data and pod regardless. This may introduce some hard-to-catch errors.
Even in the code, to which the replacement *should* be restricted,
sometimes "die" may be right and "croak" wrong. Some die()s catch
program errors, these shouldn't be attributed to the user, as croak()
does.
I shudder at the thought of going over a single source with a coarse
tool like that, not to mention carpet bombing "all .pl files" with it.
In code maintenance, you *must* inspect every change manually. Exceptions
are extremely rare.
> The list of changes to make is given to the script by an external file
> (I'll use DATA to simplify things).
>
> The naïve way I used in the beginning had to go over every file once
> for each pair of words to change, this seemed a waste so I looked for
> a way to make all the changes in one pass.
>
> Here's what I wrote, any comments are welcome.
>
> use strict;
> use warnings;
>
> # build regular expression table
> my @regexps;
> while (<DATA>) {
> my ($from, $to) = split;
> next unless $from; # blank line
> push @regexps, [ qr/\b$from\b/, $to];
> }
>
> @ARGV = glob '*.pl'; # took me a while to understand why $^I wasn't
> working...
> $^I = '.bak';
> while (<>) {
> foreach my $re (@regexps) {
> s/$$re[0]/$$re[1]/g;
"$$re[0]" would more commonly be written "$re->[0]". "$$re[0]" is correct,
but slightly ambiguous.
> }
> print;
> }
That should work, though there may be more efficient methods. See
"perldoc -q many" for some hints.
In my opinion, this technique should only be used to show (and classify,
or otherwise prepare for inspection) the places where replacements will
occur.
Anno
------------------------------
Date: 13 Apr 2004 13:07:30 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Multiple replaces
Message-Id: <u9ptac3wu5.fsf@wcl-l.bham.ac.uk>
kzin@myrealbox.com (Motti) writes:
> Here's what I wrote, any comments are welcome.
> foreach my $re (@regexps) {
> s/$$re[0]/$$re[1]/g;
> }
That is good. Many people are tempted to try to combine all the
targets into a single regex but as is hinted at in the FAQ "How do I
efficiently match many regular expressions at once?" this turns out
not to be efficient.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 13 Apr 2004 00:43:09 -0700
From: Gisle Aas <gisle@activestate.com>
Subject: Re: Need help with Parsing HTML
Message-Id: <m3smf8nx0y.fsf@eik.i-did-not-set--mail-host-address--so-shoot-me>
Bob Walton <invalid-email@rochester.rr.com> writes:
> Danny wrote:
>
> > I would like to parse an HTML file by extracting the the contents
> > of a form. Like the form objects such as the values and names
> > name = idnumber value = 4 name = productname value = scooter there
> > are a few forms per page to read in, I would like to store in an
> > array or to a text file > ...
>
>
> Modules are your friend. For this, check out the HTML::Parser module:
>
> perldoc HTML::Parser
>
> This module should already be on your hard drive.
For this specific case HTML::Form might be appropriate. It is part of
the libwww-perl distribution, and if HTML::Parser is already on your
hard drive then it is not unlikely that HTML::Form is as well.
HTML::Form will use the HTML::Parser.
--
Gisle Aas
------------------------------
Date: 13 Apr 2004 06:01:07 -0700
From: jshaboo@hotmail.com (joe shaboo)
Subject: need to find word, and comment out next 5 lines
Message-Id: <f6d34657.0404130501.35371c22@posting.google.com>
Hi,
I'm new to perl.
I need to find a line in my named.conf file, and comment out the next
five lines.
example
zone "mydomain.com" {
type master;
file "path/to/zone"
notify yes;
}
what I'd like to do
// Domain commented out by `finger `logname` | grep real | awk '{print
$7" "$8}'` on date.
// zone "mydomain.com"
// type master;
// file "path/to/zone"
// notify yes;
//}
Can someone please first, tell me can I embed system commands as I've
done?
and, lastly, how can I do this using Perl? I know it must be very
easy, but I just am not familiar enough with the language to do this.
Many Thanks,
Joe (jshaboo@hotmail.com)
------------------------------
Date: Tue, 13 Apr 2004 11:58:11 GMT
From: Don Stefani <nospam_007@yahoo.com>
Subject: Re: new bbs
Message-Id: <nBQec.51010$Rc7.15700@newssvr25.news.prodigy.com>
Robin wrote:
> http://www.infusedlight.net/robin/bbs/bbs.pl?action=view
> my latest opus. I hope you like it. I'd like to see if some hacker can hack
> this baby. I uses cgi.pm and is way more secure.
> Admin script isn't done yet.
>
> --
> Regards,
> -Robin
> --
> robin @ infusedlight.net
>
>
This is REALLY cool! But it would be really cool if you could list all of the email
addresses you use in posting here, your all over the map dude! Your like, unfiltered again.
Thanks!
ROCK ON code warrior!!!
------------------------------
Date: Tue, 13 Apr 2004 08:34:09 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: PERL web addressing
Message-Id: <rLidnRGnaNalQ-bd4p2dnA@adelphia.com>
Dale wrote:
> Anyway, the site in question has all of its links and addresses in the
> form of blah.com/index.pl/[some folder] There are no page or file type
> references visible
Yes there is. The location of the above is blah.com/index.pl - a bog
standard reference to a .pl file. The rest is just extra path info, and
available as $req->path_info() if you're using CGI.pm.
The server also translates it for you - for example, if the URL
is /index.pl/some/folder/, then $req->path_translated()
returns /doc/root/some/folder/. I don't recall if this translation takes
into account any rewrite rules, so you'll need to experiment with it if you
need that.
You can combine path info with a query string - the query comes after the
path info.
To add another level of hiding, just add a rewrite rule that transforms
blah.com into blah.com/index.pl; the above URL would then look like
blah.com/some/folder/, and your users would be none the wiser.
As the docs for CGI.pm note, these methods are broken on IIS. (Or whatever
MS is calling it this week.)
> Thoughts?
Nothing new here. I was using path info ten years ago.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 13 Apr 2004 02:23:26 -0700
From: markus.kemp@erlf.siemens.de (Markus Kemp)
Subject: Re: Question about Perl and Expect
Message-Id: <7807f68a.0404130123.1983fb7b@posting.google.com>
Right, that's me set. Thanks for replying.
------------------------------
Date: Tue, 13 Apr 2004 10:55:49 +0100
From: "bob" <mail@mail.com>
Subject: Re: SOAP:Lite Client - server message passing
Message-Id: <ACedndg8hagSJObdSa8jmw@karoo.co.uk>
I have just done somthing like this, If you mean a literal file then you can
send the file back and forth using the MIME or equivelent protocol.
"pj" <nsf470@yahoo.com> wrote in message
news:11711ebf.0404121014.39e48fe5@posting.google.com...
> Hi,
> sends a file
> SiteA: client --------------------------------> SiteB: server
> <--------------------------------
> sends a file
>
> I want to implement something like above using SOAP:Lite. I know a
> client can send a file to a server, but can server send a file to a
> client? if so, how can this be done? All I know is the return
> "message" to send a string message.
>
> I was planning to do something like the following. Each sites has SOAP
> client and server.
>
> sends a file
> SiteA: client --------------------------------> SiteB: server
> server<-------------------------------- client
> sends a file
>
> But I am wondering if it can be done with SiteA:client and
> SiteB:server.
> thanks in advance.
------------------------------
Date: 13 Apr 2004 05:35:12 -0700
From: google@milbaugh.com (GreenLight)
Subject: Re: striped name to variable
Message-Id: <c4b60ce1.0404130435.71dc3d37@posting.google.com>
sholden@flexal.cs.usyd.edu.au (Sam Holden) wrote in message news:<slrnc7m2rm.mmm.sholden@flexal.cs.usyd.edu.au>...
> > my $stripped = ($phrase =~ s/(Nick)//i);
>
> You may want to test that.
Really, I should have 8^(
Assigning to a list works for a match:
(my $stripped) = $phrase =~ /(Nick)/i;
but not for a substitution. My bad.
------------------------------
Date: Tue, 13 Apr 2004 22:09:40 +1200
From: "Tintin" <me@privacy.net>
Subject: Re: system or exec
Message-Id: <c5ge8r$1bvll$1@ID-172104.news.uni-berlin.de>
"Robin" <robin @ infusedlight.net> wrote in message
news:c5fghb$vnb$1@reader2.nmix.net...
> Which is better, overall in the ammount of time it takes for external
> command to be executed, system or exec? Later.
exec is *always* much faster as you don't have to worry about the rest of
your script running ;-)
------------------------------
Date: Tue, 13 Apr 2004 11:00:24 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: the code for bbs 3
Message-Id: <pan.2004.04.13.08.58.43.244202@aursand.no>
On Mon, 12 Apr 2004 22:42:31 -0700, Robin wrote:
> #!/usr/bin/perl
Not good enough. Use this instead:
#!/usr/bin/perl -T
#
use strict;
use warnings;
> my $string = "<--->";
> my $version = "1.0.0 (Beta)";
> my $catfile = "cats.bbs";
> my $userfile = "users.bbs";
> [...]
You should consider using constants;
perldoc constant
> &printcatfile;
Why are you calling sub-routines with '&' as a prefix? Do you know the
difference between '&printcatfile' and 'printcatfile'?
> if (! $PARAMS{'action'})
> {
> &view ("Welcome to BBS 3.");
> }
>
> elsif ($PARAMS{'action'} eq "view")
> {
> if ($PARAMS{'user'})
> {
> &view ("Welcome to BBS 3, $PARAMS{'user'}.", $PARAMS{'user'});
> }
> else
> {
> &view ("Welcome to BBS 3.");
> }
> }
>
> elsif ($PARAMS{'action'} eq "post")
> {
> if ($PARAMS{'cat'} and $PARAMS{'topic'})
> [...]
Consider using the 'Switch' module for this. Example:
my $action = $CGI->param('action') || '';
switch ( $action ) {
case 'show' { show() }
case 'edit' { edit() }
else { foo() }
}
More information:
perldoc Switch
> &printpost ("Post to category \"<b>$PARAMS{'cat'}</b>\" with topic
> \"<b>$PARAMS{'topic'}</b>\" from user account \"<b>$PARAMS{'user'}</b>\".");
Consider using a template module which lets you separate output from Perl
code. There are multiple template modules on CPAN.
> elsif ($PARAMS{'action'} eq "login")
You are constantly referring to $PARAMS{'action'} throughout the script.
Do yourself a favor and collect "globals" as early as possible in your
scripts, so that whenever you decide to change the name of the 'action'
parameter, you only have to change it once;
my $action = $PARAMS{'action'};
And - while we're at your treatment of CGI parameters: You almost never
validate them for malicious data. You should do that. Read this:
perldoc perlsec
> sub printreply
> {
> my ($replyoutput) = @_;
Why do this in an array context when you only need/use one variable? This
would do it:
sub printreply {
my $replyoutput = shift;
# ...
}
> exit;
Do you have a _good_ reason to use 'exit' in your CGI scripts? Please
read this:
perldoc -f exit
> if (! $PARAMS{'replieduser'} or ! $PARAMS{'count'} or ! $PARAMS{'cat'} or !
> $PARAMS{'topic'})
I start to shiver every time I see someone using the negate operator (?).
Using 'unless' is a lot easier to read, IMO.
> open (USERFILE, $userfile);
What happens if this fails? Always (!) check the result of 'open()'.
It's also a good thing to specify how you open the file;
open( USERFILE, '<', $userfile ) or die "$!\n";
> @usersarray = <USERFILE>;
What if it won't fit into memory?
Generally about your script: It sucks. You don't seem to know _any_ good
programming practices, and - more frightening - you seem to ignore those
who tries to teach you a trick or two.
Seeing the script itself, it would take me less than 5 minutes to "hack"
it. Not that I want to; if I ever were to hack anything, I would choose
something that would tease my brain just a little.
Do yourself a favor: Learn how to program, _then_ start programming. I'm
in doubt wether it's possible for you to teach programming at all, but...
--
Tore Aursand <tore@aursand.no>
"Life is pleasant. Death is peaceful. It's the transition that's
troublesome." -- Isaac Asimov
------------------------------
Date: Tue, 13 Apr 2004 22:11:47 +1200
From: "Tintin" <me@privacy.net>
Subject: Re: WebExplorer as Perl-CGI
Message-Id: <c5gel7$1a262$1@ID-172104.news.uni-berlin.de>
"Robin" <robin @ infusedlight.net> wrote in message
news:c5fgmh$vnh$1@reader2.nmix.net...
[no references or context]
> That's so dangerous, I've been reading up on perl-cgi security thanks to
my
> latest hackings. Good luck ruining your server. Try www.cgi-resources.com
Robin, if you persist in posting to this group, please *reread* the Posting
Guidelines, and pay particular attention quoting context.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 6394
***************************************