[28933] in Perl-Users-Digest
Perl-Users Digest, Issue: 177 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 27 06:09:57 2007
Date: Tue, 27 Feb 2007 03:09:04 -0800 (PST)
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, 27 Feb 2007 Volume: 11 Number: 177
Today's topics:
Re: a cgi for view unix logs? <robertchen117@gmail.com>
Re: a cgi for view unix logs? <paduille.4060.mumia.w+nospam@earthlink.net>
Re: any perl tool to create a flow of perl scripts <bik.mido@gmail.com>
Re: delete() on multi level hash <moritz.maisel@googlemail.com>
Re: DocumentHTML ? <joe@inwap.com>
Re: Extracting Message body from email using POP3Client simonhume@yahoo.com
Re: Fussy Date::Parse... <noreply@gunnar.cc>
new CPAN modules on Tue Feb 27 2007 (Randal Schwartz)
Posting Guidelines for comp.lang.perl.misc ($Revision: tadmc@augustmail.com
Re: problem cp <joe@inwap.com>
Re: problem cp <abigail@abigail.be>
Question about scoping <megapode@gmail.com>
updating date field in MS Access <nitte.sudhir@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 26 Feb 2007 22:25:42 -0800
From: "robertchen117@gmail.com" <robertchen117@gmail.com>
Subject: Re: a cgi for view unix logs?
Message-Id: <1172557542.335696.63140@z35g2000cwz.googlegroups.com>
On 2=D4=C214=C8=D5, =C9=CF=CE=E712=CA=B139=B7=D6, Sherm Pendley <spamt...@d=
ot-app.org> wrote:
> Andrew DeFaria <And...@DeFaria.com> writes:
>
> In HTML. Please don't do that; we're not all using HTML-aware news reader=
s=2E
> Have you read the posting guidelines for this group?
>
>
>
>
>
>
>
> > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
>
> > mailto:robertchen...@gmail.com wrote:
> > <blockquote
> > cite=3D"mid1171352707.666035.281...@a34g2000cwb.googlegroups.com"
> > type=3D"cite">I am trying to use this to output the last 100 lines to a
> > cgi page,
> > but because it do not print \n in HTML, so everything is mess up. I do
> > not want to try to open a file, read the last 100 lines and close the
> > file. Because I think it would be slow than Unix "tail".
>
> > $done =3D system("tail -100 $filename")
>
> > tail in cgi page, No return/new lines:
> ...
>
> > </blockquote>
> > Use the <pre> tag. That's what it's for!
>
> Good idea, if you want the log lines to appear as part of an enclosing web
> page. You could also just return text/plain content, if all you want is j=
ust
> the log lines, and nothing else.
>
> sherm--
>
> --
> Web Hosting by West Virginians, for West Virginians:http://wv-www.net
> Cocoa programming in Perl:http://camelbones.sourceforge.net- =D2=FE=B2=D8=
=B1=BB=D2=FD=D3=C3=CE=C4=D7=D6 -
>
> - =CF=D4=CA=BE=D2=FD=D3=C3=B5=C4=CE=C4=D7=D6 -
Tried every way you all mentioned, still not work, here is my source
codes, some of them are to initialize Tivoli env:
#!/vendor/perl/bin/perl -w
use CGI;
&tiv_init("mn");
my $q =3D CGI->new;
# HTML header and starter.
#print $q->header; print $q->start_html('View a Software Package\'s
log');
print "Content-type: text/html\n\n";
print $q->h1('View a Software Package\'s log');
print $q->start_form,
"The Software Package name: ",$q->textfield('name'),$q->br,
"View tail how many lines? ", $q->textfield('lines'),$q->br,
$q->submit('button','View Log'),
$q->end_form;
if ($q->param()) {
#print "The package is: ",$q->param('name'));
$name =3D $q->param('name');
$name =3D~ s/\^/\\^/;
$file =3D `wexpspo $name|grep log_path`;
$filename =3D $file;
$filename =3D~ s/.*?log_path.*?=3D//;
#print "The log_path is: ",$file,p,
#print "The fielname is: ", $filename,p,
#file =3D wexpspo name |grep log_file
&do_cmd(system("tail -100 $filename"));
#print $q->pre(system("tail -100 $filename")); no work
print "<pre>",@OUTPUT_LINES,"</pre>";
}
#$q->end_html();
sub do_cmd
{
@OUTPUT_LINES=3D`@_ 2>&1`;
}
sub tiv_init
{
$type =3D $_[0];
if ($type ne "" && $type eq "lcf") {
$RCFILE =3D "/etc/Tivoli/lcf/1/lcf_env.sh";
}
if ($type ne "" && $type eq "mn") {
$RCFILE =3D "/etc/Tivoli/setup_env.sh";
}
open(ENVVARS,". $RCFILE;env |");
------------------------------
Date: Tue, 27 Feb 2007 09:04:29 GMT
From: "Mumia W." <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: a cgi for view unix logs?
Message-Id: <xuSEh.7045$tD2.5777@newsread1.news.pas.earthlink.net>
On 02/27/2007 12:25 AM, robertchen117@gmail.com wrote:
> [...]
> &do_cmd(system("tail -100 $filename"));
That won't work. Try this instead:
@OUTPUT_LINES = `tail -100 $filename`;
or this:
do_cmd("tail -100 $filename")
Re-read the documentation for "system" and the "qx" operator:
perldoc -f system
perldoc -f qx
"System" does not return the output from the executed command; the qx
operator does, and backticks are an alternate form of the qx operator.
> #print $q->pre(system("tail -100 $filename")); no work
> print "<pre>",@OUTPUT_LINES,"</pre>";
> }
> #$q->end_html();
>
> sub do_cmd
> {
> @OUTPUT_LINES=`@_ 2>&1`;
> }
> [...]
BTW, gratuitous use of the shell is dangerous. Sanitize $filename before
invoking "tail."
--
Windows Vista and your freedom in conflict:
http://www.securityfocus.com/columnists/420/2
------------------------------
Date: 27 Feb 2007 02:17:46 -0800
From: "blazar" <bik.mido@gmail.com>
Subject: Re: any perl tool to create a flow of perl scripts
Message-Id: <1172571466.384349.235360@j27g2000cwj.googlegroups.com>
On 26 Feb, 18:53, "gf" <greg.fergu...@icrossing.com> wrote:
> On Feb 23, 7:50 pm, iarunku...@gmail.com wrote:
> Something like this (untested line) should work...
>
> 1 and open (my $__LOG, '>>', '/absolute/path/to/writable/log'),
> print $__LOG scalar(localtime),"\t","$0 @ARGV\n",
> close($__LOG);
[snip]
> As you get things figured out or don't want something writing to the
> log, change the leading 1 to a 0 in the code files you understand and
> that file will 'gnore the log statement.
1) At first I didn't understand the C<1 and> bit. In light of the
explanation above, I do. Yet I find it somehow confusing. People
generally use a C<DEBUG> constant set at the top of their scripts
instead. I understand that here the situation is slightly different,
because it's not a matter of debugging single scripts but a whole
bunch of them, and I see the usefluness of a simple "tag" to be
recognized and automatically changed. Anyway a thing like
use constant DEBUG => 1;
is also easy to find and replace with
use constant DEBUG => 0;
Alternatively one can use an environment variable, and even a mixed
approach like thus:
use constant DEBUG => $ENV{THIS_JOB_DEBUG};
So that she can turn it definitely on or off for individual scripts.
2) Your code as suggested won't work: a lexical variable is not
available in the same statement that defines it:
$ cat foo.pl
#!/usr/bin/perl
use strict;
use warnings;
1 and open (my $__LOG, '>>', '/absolute/path/to/writable/log'),
print $__LOG scalar(localtime),"\t","$0 @ARGV\n",
close($__LOG);
__END__
$ perl foo.pl
Global symbol "$__LOG" requires explicit package name at foo.pl line
7.
Global symbol "$__LOG" requires explicit package name at foo.pl line
8.
Execution of foo.pl aborted due to compilation errors.
Though you may convert it to something that *does* work:
if (DEBUG) {
open my $__LOG, '>>', '/absolute/path/to/writable/log'
or die "$!\n!";
print $__LOG scalar(localtime),"\t","$0 @ARGV\n",
}
3) In addition to your conceptually good suggestion, I don't know
*how* each script "calls" other ones, but the OP may want to "trap"
each of them by overloading some core functions or operators, if that
is possible.
------------------------------
Date: 27 Feb 2007 01:12:33 -0800
From: "moritz.maisel@googlemail.com" <moritz.maisel@googlemail.com>
Subject: Re: delete() on multi level hash
Message-Id: <1172567553.259376.248550@p10g2000cwp.googlegroups.com>
Hi John and Paul!
Thanks a lot for your detailed explanations!
Best regards,
Moritz
------------------------------
Date: Mon, 26 Feb 2007 23:33:47 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: DocumentHTML ?
Message-Id: <k5mdnWuNOqdDQ37YnZ2dnUVZ_sOknZ2d@comcast.com>
~greg wrote:
> But of course I use warnings!
>
> You didn't see it in my snippet because I always run scripts
> from within a text editor that has it on the command line:
> perl.exe -w -Mstrict ...
Do you expect that you will ever pass the responsibility of running those
scripts to someone else?
------------------------------
Date: 27 Feb 2007 02:04:42 -0800
From: simonhume@yahoo.com
Subject: Re: Extracting Message body from email using POP3Client
Message-Id: <1172570682.606437.25450@p10g2000cwp.googlegroups.com>
On 17 Jan, 18:25, Eadm...@letterbee.com wrote:
> Hi,
>
> I'm using pop3Client to succeessfullyextracte-mail from my mail
> server, BUT depending on the format (ie plain text, richt text or HTML)
> that they are sent, I end up with abodythat requres "massaging" with
> regular expressions to get a clean message. I am concerned that
> different systems will send me mails wilh "slightly" different formats
> and wont work with my tidy routines.
>
> Question: Has anyone got any code or can recomend a module that will
> extrcat a "clean messagebody" from theemailregardless of format /
> system sent from?
>
> Ta
>
> Eadmund
>
> Eadm...@letterbee.com
Hi,
I'm in a similar position and haven't quite figured this one out, did
you manage to find something?
I too am using the Mail::POP3Client module but by this stage I've
already dumped the email into a MySQL database.
Here's what I have:
$bodystr=index($message,"quoted-printable");
$bodyend=index($message,"</body");
if($bodystr >0) #If it's -1 then it is a plain text message
{
$bodytxt=substr($message,$bodystr+1,$bodyend-$bodystr-length("------
_=_NextPart_001_01C759B8.536E5E3B--")-2);
$bodystr=index($bodytxt,"quoted-printable");
$bodytxt2=substr($bodytxt,$bodystr+length("quoted-
printable"),length($bodytxt)-$bodystr);
$pibody.=$bodytxt2;
}else{
$pibody.=$message;
}
You can probably tell from the code, I'm new to this.
I'm still getting some extra "=" in the body of an HTML email which I
haven't investigated yet.
Thanks,
Simon.
------------------------------
Date: Tue, 27 Feb 2007 08:16:37 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Fussy Date::Parse...
Message-Id: <54i43iF20flhoU1@mid.individual.net>
DJ Stunks wrote:
> I love Date::Parse but it's struggling parsing what I consider to be a
> pretty unambiguous date time that Date::Manip handles just fine...
>
> C:\>perl -MDate::Parse \
> -e "print str2time('2/26/2007 14:38:13 PM') ? 'y' : 'n'"
--------------------------------^^-------^^
Shouldn't that be 2:38:13 PM or just 14:38:13?
To it seems like Date::Parse is doing the right thing, unlike Date::Manip.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 27 Feb 2007 05:42:10 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Tue Feb 27 2007
Message-Id: <JE3x6A.3w2@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
Class-Accessor-Classy-v0.1.2
http://search.cpan.org/~ewilhelm/Class-Accessor-Classy-v0.1.2/
accessors with minimal inheritance
----
Crypt-ECDSA-0.04
http://search.cpan.org/~billh/Crypt-ECDSA-0.04/
Elliptical Cryptography Digital Signature Algorithm
----
DBD-Informix-2007.0225
http://search.cpan.org/~johnl/DBD-Informix-2007.0225/
IBM Informix Database Driver for Perl DBI
----
DBD-Informix-2007.0226
http://search.cpan.org/~johnl/DBD-Informix-2007.0226/
IBM Informix Database Driver for Perl DBI
----
Egg-Release-1.11
http://search.cpan.org/~lushe/Egg-Release-1.11/
WEB application framework release version.
----
Google-Adwords-v1.1.1
http://search.cpan.org/~rohan/Google-Adwords-v1.1.1/
an interface which abstracts the Google Adwords SOAP API
----
KinoSearch-0.20_01
http://search.cpan.org/~creamyg/KinoSearch-0.20_01/
Search engine library.
----
MARC-XML-0.84
http://search.cpan.org/~kados/MARC-XML-0.84/
----
Math-Polynomial-Solve-2.11
http://search.cpan.org/~jgamble/Math-Polynomial-Solve-2.11/
Find the roots of polynomial equations.
----
POE-Component-Server-Chargen-1.05
http://search.cpan.org/~bingos/POE-Component-Server-Chargen-1.05/
a POE component implementing a RFC 864 Chargen server.
----
POE-Component-Server-Daytime-1.05
http://search.cpan.org/~bingos/POE-Component-Server-Daytime-1.05/
a POE component implementing a RFC 865 Daytime server.
----
POE-Component-Server-Discard-1.05
http://search.cpan.org/~bingos/POE-Component-Server-Discard-1.05/
a POE component implementing a RFC 863 Discard server.
----
POE-Component-Server-Echo-1.51
http://search.cpan.org/~bingos/POE-Component-Server-Echo-1.51/
a POE component implementing a RFC 862 Echo server.
----
POE-Component-Server-Qotd-1.05
http://search.cpan.org/~bingos/POE-Component-Server-Qotd-1.05/
a POE component implementing a RFC 865 QotD server.
----
POE-Component-Server-Time-1.05
http://search.cpan.org/~bingos/POE-Component-Server-Time-1.05/
a POE component implementing a RFC 868 Time server.
----
POE-Filter-Bzip2-1.51
http://search.cpan.org/~bingos/POE-Filter-Bzip2-1.51/
A POE filter wrapped around Compress::Bzip2
----
POE-Filter-LZF-1.61
http://search.cpan.org/~bingos/POE-Filter-LZF-1.61/
A POE filter wrapped around Compress::LZF
----
POE-Filter-LZO-1.61
http://search.cpan.org/~bingos/POE-Filter-LZO-1.61/
A POE filter wrapped around Compress::LZO
----
POE-Filter-LZW-1.61
http://search.cpan.org/~bingos/POE-Filter-LZW-1.61/
A POE filter wrapped around Compress::LZW
----
Sub-PatMat-0.01
http://search.cpan.org/~gruber/Sub-PatMat-0.01/
call a version of subroutine depending on its arguments
----
UNIVERSAL-ref-0.01
http://search.cpan.org/~jjore/UNIVERSAL-ref-0.01/
Turns ref() into a multimethod
----
WebService-FC2-SpamAPI-0.02
http://search.cpan.org/~fujiwara/WebService-FC2-SpamAPI-0.02/
FC2 blog spam API client
----
XML-Comma-1.96
http://search.cpan.org/~brianski/XML-Comma-1.96/
A framework for structured document manipulation
----
onto-perl-0.28
http://search.cpan.org/~easr/onto-perl-0.28/
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 27 Feb 2007 08:10:23 GMT
From: tadmc@augustmail.com
Subject: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.7 $)
Message-Id: <45e3e76f$0$3159$ae4e5890@news.nationwide.net>
Outline
Before posting to comp.lang.perl.misc
Must
- Check the Perl Frequently Asked Questions (FAQ)
- Check the other standard Perl docs (*.pod)
Really Really Should
- Lurk for a while before posting
- Search a Usenet archive
If You Like
- Check Other Resources
Posting to comp.lang.perl.misc
Is there a better place to ask your question?
- Question should be about Perl, not about the application area
How to participate (post) in the clpmisc community
- Carefully choose the contents of your Subject header
- Use an effective followup style
- Speak Perl rather than English, when possible
- Ask perl to help you
- Do not re-type Perl code
- Provide enough information
- Do not provide too much information
- Do not post binaries, HTML, or MIME
Social faux pas to avoid
- Asking a Frequently Asked Question
- Asking a question easily answered by a cursory doc search
- Asking for emailed answers
- Beware of saying "doesn't work"
- Sending a "stealth" Cc copy
Be extra cautious when you get upset
- Count to ten before composing a followup when you are upset
- Count to ten after composing and before posting when you are upset
-----------------------------------------------------------------
Posting Guidelines for comp.lang.perl.misc ($Revision: 1.7 $)
This newsgroup, commonly called clpmisc, is a technical newsgroup
intended to be used for discussion of Perl related issues (except job
postings), whether it be comments or questions.
As you would expect, clpmisc discussions are usually very technical in
nature and there are conventions for conduct in technical newsgroups
going somewhat beyond those in non-technical newsgroups.
The article at:
http://www.catb.org/~esr/faqs/smart-questions.html
describes how to get answers from technical people in general.
This article describes things that you should, and should not, do to
increase your chances of getting an answer to your Perl question. It is
available in POD, HTML and plain text formats at:
http://www.augustmail.com/~tadmc/clpmisc.shtml
For more information about netiquette in general, see the "Netiquette
Guidelines" at:
http://andrew2.andrew.cmu.edu/rfc/rfc1855.html
A note to newsgroup "regulars":
Do not use these guidelines as a "license to flame" or other
meanness. It is possible that a poster is unaware of things
discussed here. Give them the benefit of the doubt, and just
help them learn how to post, rather than assume that they do
know and are being the "bad kind" of Lazy.
A note about technical terms used here:
In this document, we use words like "must" and "should" as
they're used in technical conversation (such as you will
encounter in this newsgroup). When we say that you *must* do
something, we mean that if you don't do that something, then
it's unlikely that you will benefit much from this group.
We're not bossing you around; we're making the point without
lots of words.
Do *NOT* send email to the maintainer of these guidelines. It will be
discarded unread. The guidelines belong to the newsgroup so all
discussion should appear in the newsgroup. I am just the secretary that
writes down the consensus of the group.
Before posting to comp.lang.perl.misc
Must
This section describes things that you *must* do before posting to
clpmisc, in order to maximize your chances of getting meaningful replies
to your inquiry and to avoid getting flamed for being lazy and trying to
have others do your work.
The perl distribution includes documentation that is copied to your hard
drive when you install perl. Also installed is a program for looking
things up in that (and other) documentation named 'perldoc'.
You should either find out where the docs got installed on your system,
or use perldoc to find them for you. Type "perldoc perldoc" to learn how
to use perldoc itself. Type "perldoc perl" to start reading Perl's
standard documentation.
Check the Perl Frequently Asked Questions (FAQ)
Checking the FAQ before posting is required in Big 8 newsgroups in
general, there is nothing clpmisc-specific about this requirement.
You are expected to do this in nearly all newsgroups.
You can use the "-q" switch with perldoc to do a word search of the
questions in the Perl FAQs.
Check the other standard Perl docs (*.pod)
The perl distribution comes with much more documentation than is
available for most other newsgroups, so in clpmisc you should also
see if you can find an answer in the other (non-FAQ) standard docs
before posting.
It is *not* required, or even expected, that you actually *read* all of
Perl's standard docs, only that you spend a few minutes searching them
before posting.
Try doing a word-search in the standard docs for some words/phrases
taken from your problem statement or from your very carefully worded
"Subject:" header.
Really Really Should
This section describes things that you *really should* do before posting
to clpmisc.
Lurk for a while before posting
This is very important and expected in all newsgroups. Lurking means
to monitor a newsgroup for a period to become familiar with local
customs. Each newsgroup has specific customs and rituals. Knowing
these before you participate will help avoid embarrassing social
situations. Consider yourself to be a foreigner at first!
Search a Usenet archive
There are tens of thousands of Perl programmers. It is very likely
that your question has already been asked (and answered). See if you
can find where it has already been answered.
One such searchable archive is:
http://groups.google.com/advanced_group_search
If You Like
This section describes things that you *can* do before posting to
clpmisc.
Check Other Resources
You may want to check in books or on web sites to see if you can
find the answer to your question.
But you need to consider the source of such information: there are a
lot of very poor Perl books and web sites, and several good ones
too, of course.
Posting to comp.lang.perl.misc
There can be 200 messages in clpmisc in a single day. Nobody is going to
read every article. They must decide somehow which articles they are
going to read, and which they will skip.
Your post is in competition with 199 other posts. You need to "win"
before a person who can help you will even read your question.
These sections describe how you can help keep your article from being
one of the "skipped" ones.
Is there a better place to ask your question?
Question should be about Perl, not about the application area
It can be difficult to separate out where your problem really is,
but you should make a conscious effort to post to the most
applicable newsgroup. That is, after all, where you are the most
likely to find the people who know how to answer your question.
Being able to "partition" a problem is an essential skill for
effectively troubleshooting programming problems. If you don't get
that right, you end up looking for answers in the wrong places.
It should be understood that you may not know that the root of your
problem is not Perl-related (the two most frequent ones are CGI and
Operating System related), so off-topic postings will happen from
time to time. Be gracious when someone helps you find a better place
to ask your question by pointing you to a more applicable newsgroup.
How to participate (post) in the clpmisc community
Carefully choose the contents of your Subject header
You have 40 precious characters of Subject to win out and be one of
the posts that gets read. Don't waste them. Take care while
composing them, they are the key that opens the door to getting an
answer.
Spend them indicating what aspect of Perl others will find if they
should decide to read your article.
Do not spend them indicating "experience level" (guru, newbie...).
Do not spend them pleading (please read, urgent, help!...).
Do not spend them on non-Subjects (Perl question, one-word
Subject...)
For more information on choosing a Subject see "Choosing Good
Subject Lines":
http://www.cpan.org/authors/id/D/DM/DMR/subjects.post
Part of the beauty of newsgroup dynamics, is that you can contribute
to the community with your very first post! If your choice of
Subject leads a fellow Perler to find the thread you are starting,
then even asking a question helps us all.
Use an effective followup style
When composing a followup, quote only enough text to establish the
context for the comments that you will add. Always indicate who
wrote the quoted material. Never quote an entire article. Never
quote a .signature (unless that is what you are commenting on).
Intersperse your comments *following* each section of quoted text to
which they relate. Unappreciated followup styles are referred to as
"top-posting", "Jeopardy" (because the answer comes before the
question), or "TOFU" (Text Over, Fullquote Under).
Reversing the chronology of the dialog makes it much harder to
understand (some folks won't even read it if written in that style).
For more information on quoting style, see:
http://web.presby.edu/~nnqadmin/nnq/nquote.html
Speak Perl rather than English, when possible
Perl is much more precise than natural language. Saying it in Perl
instead will avoid misunderstanding your question or problem.
Do not say: I have variable with "foo\tbar" in it.
Instead say: I have $var = "foo\tbar", or I have $var = 'foo\tbar',
or I have $var = <DATA> (and show the data line).
Ask perl to help you
You can ask perl itself to help you find common programming mistakes
by doing two things: enable warnings (perldoc warnings) and enable
"strict"ures (perldoc strict).
You should not bother the hundreds/thousands of readers of the
newsgroup without first seeing if a machine can help you find your
problem. It is demeaning to be asked to do the work of a machine. It
will annoy the readers of your article.
You can look up any of the messages that perl might issue to find
out what the message means and how to resolve the potential mistake
(perldoc perldiag). If you would like perl to look them up for you,
you can put "use diagnostics;" near the top of your program.
Do not re-type Perl code
Use copy/paste or your editor's "import" function rather than
attempting to type in your code. If you make a typo you will get
followups about your typos instead of about the question you are
trying to get answered.
Provide enough information
If you do the things in this item, you will have an Extremely Good
chance of getting people to try and help you with your problem!
These features are a really big bonus toward your question winning
out over all of the other posts that you are competing with.
First make a short (less than 20-30 lines) and *complete* program
that illustrates the problem you are having. People should be able
to run your program by copy/pasting the code from your article. (You
will find that doing this step very often reveals your problem
directly. Leading to an answer much more quickly and reliably than
posting to Usenet.)
Describe *precisely* the input to your program. Also provide example
input data for your program. If you need to show file input, use the
__DATA__ token (perldata.pod) to provide the file contents inside of
your Perl program.
Show the output (including the verbatim text of any messages) of
your program.
Describe how you want the output to be different from what you are
getting.
If you have no idea at all of how to code up your situation, be sure
to at least describe the 2 things that you *do* know: input and
desired output.
Do not provide too much information
Do not just post your entire program for debugging. Most especially
do not post someone *else's* entire program.
Do not post binaries, HTML, or MIME
clpmisc is a text only newsgroup. If you have images or binaries
that explain your question, put them in a publically accessible
place (like a Web server) and provide a pointer to that location. If
you include code, cut and paste it directly in the message body.
Don't attach anything to the message. Don't post vcards or HTML.
Many people (and even some Usenet servers) will automatically filter
out such messages. Many people will not be able to easily read your
post. Plain text is something everyone can read.
Social faux pas to avoid
The first two below are symptoms of lots of FAQ asking here in clpmisc.
It happens so often that folks will assume that it is happening yet
again. If you have looked but not found, or found but didn't understand
the docs, say so in your article.
Asking a Frequently Asked Question
It should be understood that you may have missed the applicable FAQ
when you checked, which is not a big deal. But if the Frequently
Asked Question is worded similar to your question, folks will assume
that you did not look at all. Don't become indignant at pointers to
the FAQ, particularly if it solves your problem.
Asking a question easily answered by a cursory doc search
If folks think you have not even tried the obvious step of reading
the docs applicable to your problem, they are likely to become
annoyed.
If you are flamed for not checking when you *did* check, then just
shrug it off (and take the answer that you got).
Asking for emailed answers
Emailed answers benefit one person. Posted answers benefit the
entire community. If folks can take the time to answer your
question, then you can take the time to go get the answer in the
same place where you asked the question.
It is OK to ask for a *copy* of the answer to be emailed, but many
will ignore such requests anyway. If you munge your address, you
should never expect (or ask) to get email in response to a Usenet
post.
Ask the question here, get the answer here (maybe).
Beware of saying "doesn't work"
This is a "red flag" phrase. If you find yourself writing that,
pause and see if you can't describe what is not working without
saying "doesn't work". That is, describe how it is not what you
want.
Sending a "stealth" Cc copy
A "stealth Cc" is when you both email and post a reply without
indicating *in the body* that you are doing so.
Be extra cautious when you get upset
Count to ten before composing a followup when you are upset
This is recommended in all Usenet newsgroups. Here in clpmisc, most
flaming sub-threads are not about any feature of Perl at all! They
are most often for what was seen as a breach of netiquette. If you
have lurked for a bit, then you will know what is expected and won't
make such posts in the first place.
But if you get upset, wait a while before writing your followup. I
recommend waiting at least 30 minutes.
Count to ten after composing and before posting when you are upset
After you have written your followup, wait *another* 30 minutes
before committing yourself by posting it. You cannot take it back
once it has been said.
AUTHOR
Tad McClellan <tadmc@augustmail.com> and many others on the
comp.lang.perl.misc newsgroup.
------------------------------
Date: Mon, 26 Feb 2007 23:55:13 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: problem cp
Message-Id: <e86dnTAA8vt5fn7YnZ2dnUVZ_t6qnZ2d@comcast.com>
Abigail wrote:
> use File::Copy;
> copy $file => $destination;
>
> needs two lines just to copy one file, is broken, is hopelessly inflexible,
> and will delete your files if you think 'copy' might mimic the 'cp' command.
Huh? Just how can copy() cause the input file to be deleted?
-Joe
------------------------------
Date: 27 Feb 2007 10:12:09 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: problem cp
Message-Id: <slrneu80v2.aqd.abigail@alexandra.abigail.be>
Joe Smith (joe@inwap.com) wrote on MMMMCMXXVIII September MCMXCIII in
<URL:news:e86dnTAA8vt5fn7YnZ2dnUVZ_t6qnZ2d@comcast.com>:
?? Abigail wrote:
??
?? > use File::Copy;
?? > copy $file => $destination;
?? >
?? > needs two lines just to copy one file, is broken, is hopelessly inflexible,
?? > and will delete your files if you think 'copy' might mimic the 'cp' command.
??
?? Huh? Just how can copy() cause the input file to be deleted?
If you get the impression that 'copy' mimics the 'cp' command,
you might get the idea you can savely replace
copy "/etc/passwd", "/backup";
copy "/etc/shadow", "/backup";
with
copy "/etc/passwd", "/etc/shadow", "/backup";
The effect of that is that "/etc/shadow" will get truncated.
Abigail
--
perl -wle 'eval {die [[qq [Just another Perl Hacker]]]};; print
${${${@}}[$#{@{${@}}}]}[$#{${@{${@}}}[$#{@{${@}}}]}]'
------------------------------
Date: 27 Feb 2007 00:33:40 -0800
From: "Bob Dubery" <megapode@gmail.com>
Subject: Question about scoping
Message-Id: <1172565220.036099.145870@q2g2000cwa.googlegroups.com>
Hi all,
Some extracts from a program that I recently worked on follow.
The program is a "listener" that waits for data coming in on a
specific port. The incoming messages will contain 2 XML records, each
of which must be validated.
This program was exhibiting the characteristics of a memory leak. When
started up it would consume a certain amount of memory, but over time
the memory in use would grow and grow.
Here's the code I found (not the whole program) then I'll show my
changes and ask the actual question...
<code snippets start>
#! /usr/bin/perl
use strict;
use IO::Socket;
use XML::DOM;
use English;
use DBI;
use lib "/usr/local/PostOffice/progs/modules";
use QueuesDatabase;
.=2E....
.=2E....
my $line; # will contain all the input received
my $data; # will contain the current input
# get the input from the client
my $bytesRead =3D sysread($new_sock, $data, 2048);
# the data received can be more than 2048 characters, so we need to
keep reading if we havn't received the
# end of transmission character
while ($bytesRead)
{
$line =3D $line . $data;
# if it is the end of transmission, set the variable to 0 to exit
the while loop
if ($line =3D~ /$/)
{
$bytesRead =3D 0;
}
# otherwise keep reading from the socket
else
{
$bytesRead =3D sysread($new_sock, $data, 2048);
}
}
# make sure all the conditions are met
validateFile($line);
.=2E...
.=2E...
sub validateFile
{
# get the value passed to this subroutine
my $dataString =3D shift;
# remove the newline character and all other formatting characters
chomp $dataString;
$dataString =3D~ s/\t//g;
$dataString =3D~ s/\n//g;
$dataString =3D~ s/\r//g;
$dataString =3D~ s/\f//g;
# check for and remove the starting charater for the data transfer
if ($dataString =3D~ /^/) # character (0x02)
{
$dataString =3D~ s/^//; # character (0x02)
# check for and remove the ending charater for the data transfer
if ($dataString =3D~ /$/) # character (0x03)
{
$dataString =3D~ s/$//; # character (0x03)
# make sure the very first part of the file is a valid xml
header with utf-8 encoding included
unless ($dataString =3D~ /^<\?xml version=3D\"1\.0\" encoding=3D
\"UTF-8\"\?>/)
{
$errMsg =3D "Invalid xml header for the routing header.";
}
else
{
# now check for the second xml header for the body file
unless ($dataString =3D~ /<\?xml version=3D\"1\.0\" encoding=3D
\"UTF-8\"\?>/)
{
$errMsg =3D "Invalid xml header for the xml body file.";
}
else
{
# separate the xml header and xml body file into 2 different
variables
$dataString =3D~ s/^(<\?xml version=3D\"1\.0\" encoding=3D
\"UTF-8\"\?>.+)(<\?xml version=3D\"1\.0\" encoding=3D\"UTF-8\"\>.+)$/
$1$2/;
my $headerFile =3D $1;
my $bodyFile =3D $2;
# parse the xml headerFile to make sure that it is a well-
formed xml file
eval {new XML::DOM::Parser->parse($headerFile)}; # create
a new parser object and load the input file
# parser will have died with error message in $EVAL_ERROR if
XML is not well-formed
if($EVAL_ERROR)
{
$errMsg =3D "XML header file is not well-formed and can't be
processed.";
}
else
{
# parse the xml bodyFile to make sure that it is a well-
formed xml file
eval {new XML::DOM::Parser->parse($bodyFile)}; # create
a new parser object and load the input file
# parser will have died with error message in $EVAL_ERROR
if XML is not well-formed
if($EVAL_ERROR)
{
$errMsg =3D "XML body file is not well-formed and can't be
processed.";
}
}
}
}
}
else
{
$errMsg =3D "No closing flag found for the data.";
}
}
else
{
$errMsg =3D "No opening flag found for the data.";
}
}
<code snippets end>
So the program uses "strict" and 'my' is used in all the subroutines.
Now I made the following change....
<modified snippet starts>
{
# separate the xml header and xml body file into 2 different
variables
$dataString =3D~ s/^(<\?xml version=3D\"1\.0\" encoding=3D
\"UTF-8\"\?>.+)(<\?xml version=3D\"1\.0\" encoding=3D\"UTF-8\"\?>.+)$/
$1$2/;
my $headerFile =3D $1;
my $bodyFile =3D $2;
# parse the xml headerFile to make sure that it is a well-
formed xml file
my $headerXML =3D eval {new XML::DOM::Parser-
>parse($headerFile)}; # create a new parser object and load the
input file
# parser will have died with error message in $EVAL_ERROR if
XML is not well-formed
if($EVAL_ERROR)
{
$errMsg =3D "XML header file is not well-formed and can't be
processed.";
}
else
{
# parse the xml bodyFile to make sure that it is a well-
formed xml file
my $bodyXML =3D eval {new XML::DOM::Parser-
>parse($bodyFile)}; # create a new parser object and load the input
file
# parser will have died with error message in $EVAL_ERROR
if XML is not well-formed
if($EVAL_ERROR)
{
$errMsg =3D "XML body file is not well-formed and can't be
processed.";
}
else
{
$bodyXML->dispose;
}
$headerXML->dispose;
}
}
<modified snippet ends>
So what I did was to open the XML::DOM::Parser objects to variable
names and then call the dispose method once the XML has been parsed to
see if it's well formed. Result, memory usage - except for the brief
period when a document is being parsed - is more or less constant.
So my question is about the scoping in the original code. Within a
subroutine there is a line like
eval {new XML::DOM::Parser->parse($headerFile)};
How is that parser object scoped? I imagine that the author of the
code expected the object to dissappear out of memory once the
subroutine was entered.
So why the constant growth in memory usage? I can think of only two
possibilities....
1) eval {new XML::DOM::Parser->parse($headerFile)}; results in
somethong that is globally scoped
2) XML::DOM::Parser creates a whole lot of other objects/variables in
memory that persist even when the actual XML::DOM::Parser object
passes out of scope.
Or is there another reason?
Thanks
Bob
------------------------------
Date: 26 Feb 2007 22:30:13 -0800
From: "kath" <nitte.sudhir@gmail.com>
Subject: updating date field in MS Access
Message-Id: <1172557813.714277.263660@p10g2000cwp.googlegroups.com>
hi,
I am having problem in updating tables in MS Access. The field which I
want to update is of DATE type.
here is the code..
#! C:\Perl\bin\perl.exe
use Win32::ODBC;
my $db = new Win32::ODBC('ServerStatistics');
$q="select distinct(build_date) from wdf_history";
$db->Sql($q);
while($db->FetchRow)
{
$s = $db->Data();
print $s;
}
$q = "select * from wdf_history where build_date='$s'";
while($db->FetchRow)
{
$s = $db->Data();
print $s;
}
$q="update wdf_history set build_date='2007-02-27' where
build_date='$s'";
$db->Sql($q);
$q = "select * from wdf_history where build_date='$s'";
while($db->FetchRow)
{
$s = $db->Data();
print $s;
}
This does not get updated. Why?
------------------------------
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 V11 Issue 177
**************************************