[23419] in Perl-Users-Digest
Perl-Users Digest, Issue: 5637 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 8 21:05:43 2003
Date: Wed, 8 Oct 2003 18: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)
Perl-Users Digest Wed, 8 Oct 2003 Volume: 10 Number: 5637
Today's topics:
Re: C++ example in perldoc perlxs <Not_Me@freeshell.org>
Calling parent constructor <coo_t2-NO-LIKE-SPAM@yahoo.com>
counterbranding game <gugvy@opytl.org>
Re: How to get locally configured IP addresses <nospam@bigpond.com>
Re: How to get locally configured IP addresses (James Willmore)
Re: mod_perl, OO and Globals <pkent77tea@yahoo.com.tea>
Re: Newbie "undefined value" (Tad McClellan)
Re: Newbie "undefined value" (Tad McClellan)
Re: Opinions on "new SomeObject" vs. "SomeObject->new() <abigail@abigail.nl>
Re: Opinions on "new SomeObject" vs. "SomeObject->new() <abigail@abigail.nl>
Re: Opinions on "new SomeObject" vs. "SomeObject->new() <pkent77tea@yahoo.com.tea>
Re: pattern matching <invalid-email@rochester.rr.com>
Re: Problem With DBI - fetchrow_array (James Willmore)
Rookie: HTML::TableExtract test will not print <sdfg@sdg.com>
Re: Rookie: HTML::TableExtract test will not print (Tad McClellan)
Re: Rookie: HTML::TableExtract test will not print <sdfg@sdg.com>
Re: rotate items in log file (Tad McClellan)
Re: Simple Regex Problem (Tad McClellan)
Re: Sockets question <pkent77tea@yahoo.com.tea>
Re: TCP Listener on Windows XP (James Willmore)
Re: Teach me how to fish, regexp (Sam Holden)
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 09 Oct 2003 09:14:12 +1000
From: "Owen" <Not_Me@freeshell.org>
Subject: Re: C++ example in perldoc perlxs
Message-Id: <pan.2003.10.08.23.14.10.171193@freeshell.org>
On Tue, 07 Oct 2003 22:09:52 +0200, Torsten Mohr wrote:
> Can't locate auto/aMod/aMod.al in @INC (@INC contains:
> /usr/lib/perl5/5.8.0/i586-linux-thread-multi /usr/lib/perl5/5.8.0 .....
So where did you place the module?
If it is not in @INC, then you need to do something like this
use lib '/where/ever/my/module';
use aMod;
Owen
------------------------------
Date: Thu, 09 Oct 2003 00:24:59 GMT
From: ed <coo_t2-NO-LIKE-SPAM@yahoo.com>
Subject: Calling parent constructor
Message-Id: <dfa9ovsvpbh12agljhsa9mma7v49kr3as7@4ax.com>
Is there anything wrong with calling the parent's constructor
this way?
It all seems to work as expected. For instance if I take the
"printVars()" sub out of test3 the one in test2 executes.
# -- start perl code
{ package test1;
sub new
{
my $proto = shift;
my $class = ref($proto) || $proto;
my $this = {};
bless($this, $class);
print "in test1::new \n";
$this->{test1} = 'this is test1';
return $this;
}
}
{ package test2;
use base qw(test1);
sub new
{
$this = test1::new(@_);
print "in test2::new \n";
$this->{test2} = 'this is test2';
return $this;
}
sub printVars
{ my $this = shift;
print "in test2::printVars \n";
}
}
{ package test3;
use base qw(test2);
sub new
{
$this = test2::new(@_);
print "in test3::new\n";
$this->{test3} = 'this is test3';
return $this;
}
sub printVars
{ my $this = shift;
print "\$this->{test1} = $this->{test1} \n";
print "\$this->{test2} = $this->{test2} \n";
print "\$this->{test3} = $this->{test3} \n";
}
}
$obj = test3->new();
$obj->printVars();
#-- end perl code
tia,
--ed
------------------------------
Date: Thu, 8 Oct 2003 21:38:30 GMT
From: Ayub Khan <gugvy@opytl.org>
Subject: counterbranding game
Message-Id: <63bbae35.2788ec45@udigneny.org>
<HTML><!To be elder or blank will wander urban hens to lazily judge.>
<!-- Copyright 2003 The Media Foundation. All Rights Reserved -->
<HEAD><TITLE>rethink the cool</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"><LINK
title=unbrandamerica href="http://www.blackspotsneaker.org/img/01/style.css" type=text/css
rel=stylesheet><!-- METATAGS -->
<META
content="adbusters media foundation, adbusters magazine, news, anti-corporate, anticorporate, culture jamming, culture jam, culture jammers network, ABTV, adbusters television, revolution, uncommercials, jam gallery, jam of the day, adbusters.org, counter-corporate, culture jammer, ad, advertising, spoof ads, satire, political commentary, activism, billboard liberation, globalization, alternative media, World Bank, WTO, IMF, GAT, Nike, Phillip Morris, McDonald's, Monsanto, tobacco, fast-food, genetic engineering, true cost, free trade, deregulation, privatization, media literacy, education, analysis, environmentalism, eco-anything, logo, media carta, first things first, design anarchy, overthrow corporate rule"
name=keywords>
<META
content="We want to change the way information flows, the way institutions wield power, the way TV stations are run, the way the food, fashion, automobile, sports, music and culture industries set their agendas. Above all, we want to change the way we interact with the mass media and the way in which meaning is produced in our society."
name=description><!-- STYLE -->
<STYLE>#layer {
Z-INDEX: 2; LEFT: 465px; VISIBILITY: visible; WIDTH: 140px; POSITION: absolute; TOP: 216px; HEIGHT: 80px
}
BODY {
BACKGROUND: url(/navigation/navbar.gif) white repeat-x
}
</STYLE>
<SCRIPT language=JavaScript>
<!--
if (document.images) {
img1on = new Image(); img1on.src = "http://www.blackspotsneaker.org/buttons/01on.gif";
img2on = new Image(); img2on.src = "http://www.blackspotsneaker.org/buttons/02on.gif";
img3on = new Image(); img3on.src = "http://www.blackspotsneaker.org/buttons/03on.gif";
img4on = new Image(); img4on.src = "http://www.blackspotsneaker.org/buttons/04on.gif";
img5on = new Image(); img5on.src = "http://www.blackspotsneaker.org/buttons/05on.gif";
img6on = new Image(); img6on.src = "http://www.blackspotsneaker.org/buttons/06on.gif";
img7on = new Image(); img7on.src = "http://www.blackspotsneaker.org/buttons/logo1.gif";
img1off = new Image(); img1off.src = "http://www.blackspotsneaker.org/buttons/01.gif";
img2off = new Image(); img2off.src = "http://www.blackspotsneaker.org/buttons/02.gif";
img3off = new Image(); img3off.src = "http://www.blackspotsneaker.org/buttons/03.gif";
img4off = new Image(); img4off.src = "http://www.blackspotsneaker.org/buttons/04.gif";
img5off = new Image(); img5off.src = "http://www.blackspotsneaker.org/buttons/05.gif";
img6off = new Image(); img6off.src = "http://www.blackspotsneaker.org/buttons/06.gif";
img7off = new Image(); img7off.src = "http://www.blackspotsneaker.org/buttons/logo.gif";
}
function imgOn(imgName) {
if (document.images) {
document[imgName].src = eval(imgName + "on.src");
}
}
function imgOff(imgName) {
if (document.images) {
document[imgName].src = eval(imgName + "off.src");
}
}
// -->
</SCRIPT>
<!-- end STYLE -->
<!What did Claude shout the tag above the full grocer?>
<SCRIPT name="Popups">
function shoe_size()
{
window.open('http://www.blackspotsneaker.org/03/individual/chart.html','pop','width=650,height=400,menubar=no,scrollbars=yes,toolbar=no')
}
</SCRIPT>
<META content="MSHTML 6.00.2800.1170" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff><!-- NAVIGATION -->
<TABLE cellSpacing=0 cellPadding=0 width=750 bgColor=#000000 border=0>
<TBODY>
<TR vAlign=top>
<TD align=left width=180><A onmouseover="imgOn('img7');"
onmouseout="imgOff('img7')" href="http://adbusters.org/home"><IMG
height=30 alt=Adbusters src="http://www.blackspotsneaker.org/buttons/logo.gif" width=140 border=0
name=img7></A> </TD>
<TD noWrap align=left width=420>
<TABLE cellSpacing=0 cellPadding=0 width=570 border=0>
<TBODY>
<TR>
<TD align=left width=381><A onmouseover="imgOn('img1');"
onmouseout="imgOff('img1')"
href="http://adbusters.org/campaigns/"><IMG height=30 alt=Campaigns
src="http://www.blackspotsneaker.org/buttons/01.gif" width=74 border=0 name=img1></A><A
onmouseover="imgOn('img2');" onmouseout="imgOff('img2')"
href="http://adbusters.org/magazine/"><IMG height=30 alt=Magazine
src="http://www.blackspotsneaker.org/buttons/02.gif" width=69 border=0 name=img2></A><A
onmouseover="imgOn('img3');" onmouseout="imgOff('img3')"
href="http://adbusters.org/creativeresistance/"><IMG height=30
alt="Creative Resistance" src="http://www.blackspotsneaker.org/buttons/03.gif" width=127
border=0 name=img3></A><A onmouseover="imgOn('img5');"
onmouseout="imgOff('img5')"
href="https://secure.adbusters.org/orders/"><IMG height=30
alt=Orders src="http://www.blackspotsneaker.org/buttons/05.gif" width=70 border=0
name=img5></A></TD>
<TD align=right width=189><A onmouseover="imgOn('img6');"
onmouseout="imgOff('img6')"
href="http://adbusters.org/information/"><IMG height=30
alt=Information src="http://www.blackspotsneaker.org/buttons/06.gif" width=39 border=0
name=img6></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR><!-- end NAVIGATION --><BR>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD width=60></TD>
<TD class=px15 width=400><B><BR>This is a ground-breaking marketing scheme
to uncool Nike. If it succeeds, it will set a precedent that will
revolutionize capitalism. <BR></B></TD>
<TD align=right width=250></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=750 border=0>
<TBODY>
<TR>
<TD align=middle><BR><BR><IMG height=333 alt=""
src="http://www.blackspotsneaker.org/img/01/shoe05.jpg" width=712 border=0><BR><BR><BR><IMG
height=193 alt="" src="http://www.blackspotsneaker.org/img/01/phil_knigh_had_a_dream.gif" width=475
border=0><BR><BR><BR></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=750 border=0>
<TBODY>
<TR>
<TD></TD>
<TD class=px15 width=400><B>For years, Nike was the undisputed champion of
logo culture, its swoosh an instant symbol of global cool. Today, Phil
Knight's Nike is a fading empire, badly hurt by years of "brand damage" as
activists and culture jammers fought back against mindfuck marketing and
dirty sweatshop labor.<BR><BR>Now a final challenge. We take on Phil at
his own game - and win. We turn the shoes we wear into a counterbranding
game. The swoosh versus the anti-swoosh. Which side are you
on?<BR><BR>Adbusters has been doing R&D for more than a year, and
guess what? Making a shoe - a good shoe - isn't exactly rocket science.
With a network of supporters, we're getting ready to launch the
<I>blackSpot</I> sneaker, the world's first grassroots anti-brand. You can
help launch the <I>blackSpot</I> revolution.<BR><BR>THE BIG
QUESTION:<BR>Is it possible to take Phil Knight's billion-dollar marketing
momentum and, in a quick judo-like move, slap him onto the mat with the
power of his own PR thrust?<BR><BR><A
href="http://blackspotsneaker.org/02/">OUR KICK-ASS MARKETING
STRATEGY>><BR></A><BR></B></TD>
<TD align=left></TD></TR></TBODY></TABLE><BR><BR>
</BODY>
</HTML>
<!Frederic, have a cold sauce. You won't expect it.>
me who I was I told him that
I am 7th star, all this time I thought I was dreaming. Because they had
changed their tactic they could not make me speak so they told me I was
dreaming and thus started finding out what I knew.
He brough a cassette player and this radio player kept repeating one
message again and agian, when I was being electrified. By the way he
gave me various kind of injections and the injection to erase my memory
was given to me three times in those three nights, each time a much
bigger dose, as I was not forgetting what they were doing to me.
May God free the world soon and then the days of these liar, cowardly
coward Hayenas who have raped Christainity and Islam in the name of
Israel, to satify their jealosy and corrupt and control the human race.
wa'Salam Mohsin
Welcome to organised terror/ car bomb
Assalam u'Alekum all,
In early April 2002(last year), a car bomb exploded just outside the
Australian Embassy in Pakistan. Guess who was behind organising this
bomb, I heard a few people died when this bomb exploded. Abu Omar was
behind this event. It is said that he followed me, after I had left to
go to Pakistan, he had arranged this terrorist act from Australia,
special thanks to this "jewish" brothers in Pakistan. I bet every
oridnary person in Australia must have though it is Muslims, well now
you know.
I have also been told that he traveled all this way, to actually kill me
in Pakistan and rape people around me. He was successful in raping one
of my relatives, apparently my step sister, we are gathering more
information and I will let you know more details soon. So far I have
been told that he actually forced the person who was raped. Do you
believe this jew travelled all this way to rape my family members, GG
was very well aware of what was going on, he actually supported this
man, that is why weak cops like McMahn couldn't do much about stopping
Abu Omar,
------------------------------
Date: Thu, 09 Oct 2003 08:26:59 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: How to get locally configured IP addresses
Message-Id: <3014073.THtPdskL8Y@gregs-web-hosting-and-pickle-farming>
It was a dark and stormy night, and A. Ma managed to scribble:
> Does anyone know how to find out what IP addresses are configured locally?
> Thanks.
>
> A.Ma
In linux, ifconfig;
In Perl, system('ifconfig');
gtoomey
------------------------------
Date: 8 Oct 2003 16:18:27 -0700
From: jwillmore@cyberia.com (James Willmore)
Subject: Re: How to get locally configured IP addresses
Message-Id: <e0160815.0310081518.5507e22f@posting.google.com>
"A. Ma" <ama@PW.CA> wrote in message news:<bm1bt3$dhh21@shark.pwgsc.gc.ca>...
> Does anyone know how to find out what IP addresses are configured locally?
> Thanks.
>
> A.Ma
In Perl? Using a system command? What?
What methods have you tried? Did you search for the answer to your
question? If so, where?
You may far better posting this _exact_ question to another group -or-
rephrase the question into one that this group deals with.
Jim
------------------------------
Date: Thu, 09 Oct 2003 00:49:49 +0100
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: mod_perl, OO and Globals
Message-Id: <pkent77tea-8F4F64.00494909102003@pth-usenet-02.plus.net>
In article <v7Ngb.76$_z4.6584@news.optus.net.au>, "M2" <m2@nowhere.com>
wrote:
> I'm looking for a way to store some common objects (e.g. a database handle)
> in such a way that it may be accessed from anywhere within an OO based
> mod_perl application.
Just keep the data in package globals, and it can persist as long as the
mod_perl child exists. It also doesn't matter that your application is
OO, or not, or only partly, if you were wondering.
Don't forget you can also tie hashes to DBMs, or serialize data
structures to disk if you want disk-backed caching.
P
--
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply
------------------------------
Date: Wed, 8 Oct 2003 17:59:43 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Newbie "undefined value"
Message-Id: <slrnbo95mv.luh.tadmc@magna.augustmail.com>
Nadine <nadine@mail.sdsu.edu> wrote:
> I get a "cannot use undefined value as symbol ref at line 45."
That is not the message you got, why lie to us like that?
What is the *exact* message text?
(We might need to look it up in perldiag.pod. Have you tried that? )
Was this the actual message:
Can't use an undefined value as symbol reference at...
??
Do you us expect to count to find out where line 45 is?
You should have marked it or something if you wanted to
maximize the number of people that will take the time
to look at it.
Have you seen the Posting Guidelines that are posted here frequently?
> From the command line, my syntax
> checks out as OK.
Because the error is a run-time error, not a compile-time one.
> I thought "strict" would catch all
> undefined variables.
What documentation did you read that led you to believe that?
"use strict" has nothing to do with undefined variables
(it has to do with un_declared_ variables).
> #!/usr/bin/perl -w
> use warnings;
Use one or the other, not both.
(use warnings is "better" than -w).
> my(
> $DATAFILE,
[snip many lines of code]
> # give path and name of data file
> $DATAFILE="Eval.dat";
It is good programming practice to limit the scope of variables
as much as is possible, so you should declare them near where
you use them:
my $DATAFILE = 'Eval.dat';
Single quotes are better than double quotes, unless you need one
of the two "extra" things that double quotes gives you.
Spaces around operators make code easier to read.
> sub write_datafile {
That is a strange name for a function that does not write to a data file...
> my $fh = filelock($DATAFILE,1);
> unless ($fh) {
> print strong('Sorry, an error occurred: unable to open file.'),p();
> Delete('action');
> print a({-href=>self_url},'Try again');
> return undef;
> }
> }
[snip]
> print $fh "$value . |\n";
Is this your real code?
Do you want to print a dot between $value and the vertical bar?
Did you mean:
print $fh $value . "|\n";
or
print $fh $value, "|\n";
or
print $fh "$value|\n"; # preferred
instead?
> unlock($fh);
Uh oh...
> sub filelock {
> my $path = shift;
> my $for_writing = shift;
or: my( $path, $for_writing ) = @_;
> sub unlock {
> my $fh = shift;
> flock($fh,LOCK_UN);
There is a race here, between releasing the lock and closing
the filehandle.
You shouldn't unlock, close() will unlock _and_ close for you.
> close $fh;
> }
>
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 8 Oct 2003 18:29:09 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Newbie "undefined value"
Message-Id: <slrnbo97e5.m44.tadmc@magna.augustmail.com>
Malcolm Dew-Jones <yf110@vtn1.victoria.tc.ca> wrote:
> Nadine (nadine@mail.sdsu.edu) wrote:
>: Hello,
>
>: I thought "strict" would catch all
>: undefined variables. I am using Perl 5 and Apache.
>
> Yes, it catches all undefined * variables *.
s/defined/declared/
( but it doesn't really catch _all_ undeclared variables either.
eg: $main::secret = 42; # is fine by use strict...
)
> You have an undefined * value *.
Right.
> The variable name has been defined,
s/defined/declared/
> but you are trying to use the value
> before you have given it a value. Often this indicates an error, but the
> error cannot (in general) be found until the program is running.
Right.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 08 Oct 2003 22:57:33 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Opinions on "new SomeObject" vs. "SomeObject->new()"
Message-Id: <slrnbo95is.35g.abigail@alexandra.abigail.nl>
Randal L. Schwartz (merlyn@stonehenge.com) wrote on MMMDCLXXXIX September
MCMXCIII in <URL:news:51a53c247078236ccbf45909c38c6207@news.teranews.com>:
__
__ Don't make $instance->new. It obscures more than it communicates.
Then don't use it. The fact that the author of a module makes
$instance -> new possible is a convenience to the user of the
module. But not a requirement to use it.
If you get confused by s///e, don't use it.
If you get confused by map in void context, don't use it.
If you get confused by $instance -> new, don't use it.
Larry has said it's ok to talk baby Perl. But that doesn't mean
that people who like to speak adult Perl should be prohibited
to do so.
Abigail
--
$_ = "\x3C\x3C\x45\x4F\x54" and s/<<EOT/<<EOT/e and print;
Just another Perl Hacker
EOT
------------------------------
Date: 08 Oct 2003 23:15:37 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Opinions on "new SomeObject" vs. "SomeObject->new()"
Message-Id: <slrnbo96ko.35g.abigail@alexandra.abigail.nl>
Matija Papec (perl@my-header.org) wrote on MMMDCLXXXIX September MCMXCIII
in <URL:news:gj06ov8h7gkrgv458kt9hda03n53senaj2@4ax.com>:
<>
<> As for cargo cult programming, how about some general programming guidelines
<> which should have community consensus? Like perlstyle.pod which could make
<> some guidelines more official?
Please no. *Personal* programming guidelines are ok. But let's not wade
into the swamps of trying to derive guidelines with community consensus.
Remember that are hundreds of thousands of Perl programmers, but only a
few hundred of them are active on Perl forums - but there are dozens of
those forums.
At best you reach consensus between an insignificant fraction of the
"community", but you'll falsely label it as a "generally accepted
style guide". If you want a language that comes with a notion on what
is good style, and what should be avoided, you find it thataway --->
www.python.org.
Anyway, I do have some personal guidelines. People who have heard my
talk at this years YAPC::NA already know it, but I'd include it here.
Note that these are *my* guidelines, and I'm not trying to enforce
them on anyone else. Nor do I want to claim they have "community
consensus".
=over 4
=item Warnings SHOULD be turned on.
Turning on warnings helps you finding problems in your code. But it's
only useful if you understand the messages generated. You should also
know when to disable warnings - they are warnings after all, pointing
out potential problems, but not always bugs.
=item Larger programs SHOULD use strictness.
The three forms of strictness can help you to prevent making certain
mistakes by restricting what you can do. But you should know when it
is appropriate to turn off a particular strictness, and regain your
freedom.
=item The return values of system calls SHOULD be checked.
NFS servers will be down, permissions will change, file will
disappear, disk will fill up, resources will be used up.
System calls can fail for a number of reasons, and failure is
not uncommon. Programs should never assume a system call will
succeed - they should check for success and deal with failures.
The rare case where you don't care whether the call succeeded
should have a comment saying so.
All system calls should be checked, including, but not limited
to, C<close>, C<seek>, C<flock>,
C<fork> and C<exec>.
=item Programs running on behalf of someone else MUST use tainting;
Untaining SHOULD be done by checking for allowed formats.
Daemons listening to sockets (including, but not limited to CGI programs)
and suid and sgid programs are potential security holes. Tainting can
help securing your programs by tainting data coming from untrusted
sources. But it's only useful if you untaint carefully: check for
accepted formats.
=item Programs MUST deal with signals appropriately.
Signals can be sent to the program. There are default actions - but
they are not always appropriate. If not, signal handlers need to be
installed. Care should be taken since not everything is reentrant.
Both pre-5.8.0 and post-5.8.0 have their own issues.
=item Programs MUST deal with early termination appropriately.
C<END> blocks and C<__DIE__> handlers should be used
if the program needs to clean up after itself, even if the program terminates
unexpectedly - for instance due to a signal, an explicite C<die>
or a fatal error.
=item Programs MUST have an exit value of 0 when running succesfully,
and a non-0 exit value when there's a failure.
Why break a good UNIX tradition? Different failures should have different
exit values.
=item Daemons SHOULD never write to STDOUT or STDERR but SHOULD use
the syslog service to log messages. They should use an
appropriate facility and appropriate priorities when logging
messages.
Daemons run with no controlling terminal, and usually its standard
output and standard error disappear. The syslog service is a standard
UNIX utility especially geared towards daemons with a logging need.
It allows the system administration to determine what is logged, and
where, without the need to modify the (running) program.
=item Programs SHOULD use Getopt::Long to parse options. Programs
MUST follow the POSIX standard for option parsing.
Getopt::Long supports historical style arguments (single dash, single
letter, with bundling), POSIX style, and GNU extensions.
Programs should accept reasonable synonymes for option names.
=item Interactive programs MUST print a usage message when called
with wrong, incorrect or incomplete options or arguments.
Users should know how to call the program.
=item Programs SHOULD support the C<--help> and
C<--version> options.
C<--help> should print a usage message and exit,
while C<--version> should print the version number of the program.
=item Code SHOULD have an exhaustive regression test suite.
Regression tests help catch breakage of code. The regression tests
should 'touch' all the code - that is, every piece of code should be
executed when running the regression suite. All border should be checked.
More tests is usually better than less test. Behaviour on invalid inputs
needs to be tested as well.
=item Code SHOULD be in source control.
And a code source control tool will take care of keeping track of a history
or changes log, version numbers and who made the most recent change(s).
=item All database modifying statements MUST be wrapped inside a
transaction.
Your data is likely to be more important than the runtime or codesize
of your program. Data integrety should be retained at all costs.
=item Subroutines in standalone modules SHOULD perform argument checking
and MUST NOT assume valid arguments are passed.
Perl doesn't compile check the types of or even the number of arguments.
You will have to do that yourself.
=item Objects SHOULD NOT use data inheritance unless it is appropriate.
This means that "normal" objects, where the attributes are stored inside
anonymous hashes or arrays should not be used. Non-OO programs benefit
from namespaces and strictness, why shouldn't objects? Use objects based
on keying scalars, like fly-weight objects, or inside-out objects.
You wouldn't use public attributes in Java all over the place either,
would you?
=item Comment SHOULD be brief and to the point.
If you need lots of comments to explain your code, you may consider
rewriting it. Subroutines that have a whole blob of comments describing
arguments are return values are suspect. But do document invariants, pre-
and postconditions, (mathematical) relationships, theorems, observations
and other relevant things the code assumes. Variables with a broad scope
might warrant comments too.
=item POD SHOULD not be interleaved with the code, and is not an alternative
for comments.
Comments and POD have two different purposes. Comments are there for
the programmer. The person who has to maintain the code. POD is there
to create user documentation from. For the person using the code.
POD should not be interleaved with the code because this makes it harder
to find the code.
=item Comments, POD and variable names MUST use English.
English is the current Lingua Franca.
=item Variables SHOULD have an as limited scope as is appropriate.
"No global variables", but better. Just disallowing global variables
means you can still have a loop variant with a file-wide scope. Limiting
the scope of variables means that loop variants are only known in the
body of the loop, temporary variables only in the current block, etc.
But sometimes it's useful for a variable to be global, or have a
file-wide scope.
=item Variables with a small scope SHOULD have short names, variables
with a broad scope SHOULD have descriptive names.
C<$array_index_counter> is silly;
C<for (my $i = 0; $i < @array; $i ++) { .. }> is perfect.
But a variable that's used all over the place needs a descriptive
name.
=item Constants (or variables intended to be constant) SHOULD have names
in all capitals, (with underscores separating words), so SHOULD
IO handles. Package and class names SHOULD use title case, while other
variables (including subroutines) SHOULD use lower case, words separated
by underscores.
This seems to be quite common in the Perl world.
=item Custom delimiters SHOULD be tall and skinny.
C</>, C<!>, C<|> and the four sets of
braces are acceptable, C<#>, C<@> and C<*>
are not. Thick delimiters take too much attention. An exception is made
for: C< q $Revision: 1.1.1.1$>, because RCS and CVS scan for
the dollars.
=item Operators SHOULD be separated from their operands by whitespace,
with a few exceptions.
Whitespace increases readability. The exceptions are:
=over 4
=item Unary C<+>, C<->, C<\>, C<~> and C<!>.
=item No whitespace between a comma and its left operand.
=back
Note that there is whitespace between C<++> and C<-->
and their operands, and between C<->> and its operands.
=item There SHOULD be whitespace between an identifier and its indices.
There SHOULD be whitespace between successive indices.
Taking an index is an operation as well, so there should be whitespace.
Obviously, we cannot apply this rule in interpolative contexts.
=item There SHOULD be whitespace between a subroutine name and its parameters,
even if the parameters are surrounded by parens.
Again, readability.
=item There SHOULD NOT be whitespace after an opening parenthesis, or
before a closing parenthesis. There SHOULD NOT be whitespace after
an opening indexing bracket or brace, or before a closing indexing
bracket or brace.
That is: C<$array [$key]>, C<$hash {$key}> and
C<sub ($arg)>.
=item The opening brace of a block SHOULD be on the same line as the keyword
and the closing brace SHOULD align with the keyword, but short blocks
are allowed to be on one line.
This is K&R style bracing, except that we require it for subroutines as well.
We do allow C<map {$_ * $_} @args> to be on one line though.
=item No cuddled elses or elsifs. But the C<while> of a
C<do { } while> construct should be on the same line
as the closing brace.
It just looks better that way! C<;-)>
=item Indents SHOULD be 4 spaces wide. Indents MUST NOT contain tabs.
4 spaces seems to be an often used compromise between the need to make
indents stand out, and not getting cornered. Tabs are evil.
=item Lines MUST NOT exceed 80 characters.
There is just no excuse for that. More than 80 characters means it
will wrap in too many situations, leading to hard to read code.
=item Align code vertically.
This makes code look more pleasing, and it brings attention to the
fact similar things are happening on close by lines. Example:
my $var = 18;
my $long_var = "Some text";
=back
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
------------------------------
Date: Thu, 09 Oct 2003 01:15:42 +0100
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: Opinions on "new SomeObject" vs. "SomeObject->new()"
Message-Id: <pkent77tea-483F44.01154209102003@pth-usenet-02.plus.net>
In article <2003Oct7.184133@ukwit01>, gml4410@ggr.co.uk (Lack Mr G M)
wrote:
> Except that it is actually:
>
> $new_object = new Class;
>
> and you are *not* asking for a new class.
No, but imagine a better example that uses a slightly better name, like
where I have a class representing Employees. To create a new instance of
an employee I can say:
my $scott = new Employee( Password => 'tiger' );
or of course:
my $scott = Employee->new( Password => 'tiger' );
So in that less abstract example I'm not asking for a new _class_, I'm
asking for a new employee, i.e. a new thing of a certain kind. But at
least with perl you can choose the syntax that you prefer, or that makes
most sense in a given application (like the login tokens example you
give) - you probably can't have one hard and fast rule for every single
case.
Also the use of 'new' as a constructor is just a common convention, but
my constructor can be called anything:
my $scott = existing Employee( ID => '211' );
It's probably terrible to suggest that constructors need not be methods
at all, but could in fact be plain routines:
my $scott = Employee::existing( ID => '211' );
# $scott is an object
but you can do it - there are reasons not to do it :-)
P
--
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply
------------------------------
Date: Thu, 09 Oct 2003 00:35:15 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: pattern matching
Message-Id: <3F84ABBC.1000607@rochester.rr.com>
Lex wrote:
> "Bob Walton" <invalid-email@rochester.rr.com> wrote in message
> news:3F837912.5060402@rochester.rr.com...
>
...
> I know I can install perl on my windows machine, but I reckon for my scripts
> to run (at the end they have to work on a unix-like machine) with all the
> path info and stuff it's not worth testing them first on my machine and than
> upload and see that stuff doesn't work as it isn't a windows webserver...
...
> Lex
You are overestimating the changes required when running Perl on a Unix
versus Windoze platform. I, for example, have run everything associated
with your problem (and most all the others) on Windoze 98SE (I do boot
to Linux sometimes, but not usually because of Perl). The Perl
development folks have done a stellar job of making Perl as
OS-independent as possible -- for example, the / versus \ path seperator
issue is a non-issue internally in Perl -- Perl does what you mean. The
only important exception is with binary files -- you must use the
binmode() function when dealing with binary files on Windoze.
It is super easy to get and install Perl on a Windoze machine -- one
option is visiting http://www.activestate.com and downloading their
version of Perl. If you have an older version of Windoze, you may need
to also download the "Micro$loth Installer" first, but that is spelled
out in relatively clear instructions on the site. Within minutes of
completing the download you can have Perl up and going, complete with
all the standard modules and real nice HTML docs. The only caution is
to not install a newer version of Perl over top of an older version --
that doesn't seem to fly too well.
You will find it 1000% easier to debug your scripts on your local
machine than on someone else's remote web server. And you can install a
web server on your own computer to assist with debugging CGI scripts
when they are actually running in a CGI environment. Trust me, it will
save you gobs of time to take the time to install Perl on your local
machine.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: 8 Oct 2003 16:14:45 -0700
From: jwillmore@cyberia.com (James Willmore)
Subject: Re: Problem With DBI - fetchrow_array
Message-Id: <e0160815.0310081514.368e84b6@posting.google.com>
"Pisinho" <linux@fol.it> wrote in message news:<bm1ijb$49n$1@newsreader.mailgate.org>...
> "James Willmore" <jwillmore@cyberia.com> ha scritto nel messaggio
> news:e0160815.0310080715.7a3a7a11@posting.google.com...
> > "Pisinho" <linux@fol.it> wrote in message
> news:<bm0atv$2qc$1@newsreader.mailgate.org>...
> > > I have thi script, but when I invoke this sub query i have the error:
> > >
> > > DBD::mysql::st fetchrow_array failed:fetch() without execute() at
> > > database.pl line 16, <FILE> line 42
> > >
>
> With execute() or return 0; I have this error:
>
> DBI::HASH(0x....)
>
> What is?
And did you do as suggested - reading the DBI documentation? Did you,
maybe, change your 'connect' method to what I posted earlier? If so,
did your error message change?
You could also use the 'trace' method (which is described in the DBI
documentation) to see if, maybe, there is an issue with you making the
connection to the database.
The error appears, to me, that the connection to the database failed,
you didn't catch the error, now you're going to 'execute' an SQL query
without a valid database connection. However, using the 'trace'
method and changing your connection statement will (dis)prove what I
have said.
HTH
Jim
------------------------------
Date: Wed, 08 Oct 2003 22:46:36 GMT
From: "sdfgsd" <sdfg@sdg.com>
Subject: Rookie: HTML::TableExtract test will not print
Message-Id: <gt0hb.71562$Of2.2936412@twister.tampabay.rr.com>
Hello,
This script will not generate any output within the foreach loop. No errors
or anything. $te tests ok with a hash. I can't figure it out.
My sample .html file consists of 1 table (depth = 0, count = 0). Using perl
5.8/Suse 8.0
Thanks in Advance
===========================
#!/usr/bin/perl
use warnings;
use strict;
use HTML::TableExtract;
my $target = "op2.html";
my $te;
my $ts;
my $row;
if (-e $target) { print "File Exists\n"; }
$te = new HTML::TableExtract( depth => 0, count => 0 );
$te->parse($target);
print "We are here\n";
foreach $ts ($te->table_states) {
print "Table found at ", join(',', $ts->coords), ":\n";
foreach $row ($ts->rows) {
print " ", join(',', @$row), "\n";
}
}
============================
------------------------------
Date: Wed, 8 Oct 2003 18:24:32 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Rookie: HTML::TableExtract test will not print
Message-Id: <slrnbo975g.m44.tadmc@magna.augustmail.com>
sdfgsd <sdfg@sdg.com> wrote:
> This script will not generate any output within the foreach loop.
Your code looks OK to me. Must be the data (that we weren't given).
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 08 Oct 2003 23:39:16 GMT
From: "sdfgsd" <sdfg@sdg.com>
Subject: Re: Rookie: HTML::TableExtract test will not print
Message-Id: <Ee1hb.81727$eS5.79602@twister.tampabay.rr.com>
> Your code looks OK to me. Must be the data (that we weren't given).
Thanks for the follow-up. I'm hoping I can get this to work because this
looks like a phenomonal tool...as opposed to having to write a new state
machine/parser :-)
The .html file looks like this:
=============================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
</body>
</html>
------------------------------
Date: Wed, 8 Oct 2003 16:11:28 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: rotate items in log file
Message-Id: <slrnbo8vc0.luh.tadmc@magna.augustmail.com>
Robert Wallace <robertw@nospam.acm.org> wrote:
> Tad McClellan wrote:
>> Is logging going on while
>> you are rotating the log?
> you think it'll be a problem without locking?
If you answer my question, then I will answer your question.
(the reason for asking the question was to determine whether
there might be a problem. But you did not answer it, so I
don't know if it will be a problem or not...
)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 8 Oct 2003 16:05:36 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Simple Regex Problem
Message-Id: <slrnbo8v10.luh.tadmc@magna.augustmail.com>
James E Keenan <jkeen@concentric.net> wrote:
> Robert <rob@nospam.here> wrote in message news:<ibp7ov0qcuq7quoq6jtugamd177tdhgvdh@4ax.com>...
>> Given a list of vehicles I need to capitalise the first letter of the
>> make and model and change the spec to uppercase.
>> The closest I can get is this but it capitalises every word.
>>
>> $model =~ s/(\w+)/\u\L$1/g;
^^
^^ aka: ucfirst()
>> Any pointers would be appreciated.
>
> Have you consulted this item in the docs?
>
> perldoc -f ucfirst
He is already using ucfirst().
Your followup does not address the question that was asked, namely
how to treat the "spec" differently from the make and model.
(the "spec" could be called a "trim level" in the automotive biz)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 09 Oct 2003 01:28:28 +0100
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: Sockets question
Message-Id: <pkent77tea-007705.01282809102003@pth-usenet-02.plus.net>
In article <_QTgb.141720$bo1.91274@news-server.bigpond.net.au>,
"John" <no@spam.here> wrote:
> One of the exercises in front of me is:
> "Write a server in perl that will send the client a sleepy string of
> "ZZZZZZZZZ" whenever it connects using port 54321 from the same host using a
> socket in the UNIX domain."
Hang on, aren't Unix domain sockets (when named) things on your
filesystem, and therefore there is no port number? TCP and UDP
sockets/connections have port numbers associated with them, but I
thought Unix domain sockets didn't. I may have missed something in the
perlipc page though, as I don't really use these kinds of sockets.
P
--
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply
------------------------------
Date: 8 Oct 2003 17:06:17 -0700
From: jwillmore@cyberia.com (James Willmore)
Subject: Re: TCP Listener on Windows XP
Message-Id: <e0160815.0310081606.5edb99f7@posting.google.com>
"Colin Robbins" <C.J.Robbins@ntlworld.com> wrote in message news:<A_Egb.101$B71.34@newsfep1-gui.server.ntli.net>...
> I have a network application that works fine on Linux, and I want to run it
> on on a Windows XP machine. For some reason I cannot get the TCP listener
> to respond.
>
> I have cut the code down to the bare minimum to try and debug...
>
> use IO::Socket;
> use Net::hostent;
> $PORT = 2345;
> $server = IO::Socket::INET->new( Proto => 'tcp',
> LocalPort => $PORT,
> Listen => SOMAXCONN,
> Reuse => 1);
> die "can't setup server" unless $server;
> print "[Server $0 accepting clients]\n";
> while ($client = $server->accept()) {
> $hostinfo = gethostbyaddr($client->peeraddr);
> printf "Connect from %s\n", $hostinfo->name ||
> $client->peerhost;
> $line = <$client>;
> print "Got: $line \n";
> close $client;
> }
>
> When I run this, and connect a client, I get as far as the "Connect from..."
> message, but the $line=<$client> never returns anything.
>
> Any ideas why this will not work on XP?
>
> I am using ActivState perl 5.8.0.
The code is fine. I tested with a W2K box and connected just fine
using Linux. However, I found that the native W2K telnet client
doesn't echo. The line is printed on the server side, but the client
... well ... you have no idea what you typed until you hit enter.
That's the key ... are you using a client that sends a new line at the
end of a line -or- is it some other character? That may be the issue.
Jim
------------------------------
Date: 8 Oct 2003 23:15:01 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Teach me how to fish, regexp
Message-Id: <slrnbo96jk.ep2.sholden@flexal.cs.usyd.edu.au>
On Wed, 08 Oct 2003 19:21:02 GMT, Henry <henryn@zzzspacebbs.com> wrote:
>
> That said, I have to say I find the man pages the last place I want to look
> in terms of convenience. I'll have to find a web based... Done!
The risj with that is that the man pages on your system will document
the perl installed on your system. The web versions will document
some version of perl which might not be the one you are using.
Plus the man pages also document the modules you have installed, rather than
a random selection of them...
>
> Ah, much easier. Here's a relevant extract.
>
> ...Setting to "" will treat two or more consecutive empty lines as a single
> empty line. Setting to "\n\n" will blindly assume that the next input
> character belongs to the next paragraph, even if it's a newline. (Mnemonic:
> / delimits line boundaries when quoting poetry.)
>
> Quoting _poetry_?
Why not. It's true after all, and hence a reasonable mnemonic.
>
> The choice of "" as a special is clearly a choice of convenience on the part
> the people doing the internals-- and has no particular mnemonic or symbolic
> values. I'm glad that's clear.
"" and undef are the only two values that could be used as something special,
since everything else is a possible literal end of line marker.
undef as "slurp" mode makes sense, since that's more common than paragraph
mode (in my experience anyway) and being undef means a simple 'local $/;'
is enough to enable it.
That leaves "" for something else, and paragraph mode is a good choice in
my opinion, since it's a reasonably commonly wanted operation.
Of course when references arrived a new possibility became available and
(since it's perl) was used...
--
Sam Holden
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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.
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 5637
***************************************