[22174] in Perl-Users-Digest
Perl-Users Digest, Issue: 4395 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 13 14:10:43 2003
Date: Mon, 13 Jan 2003 11:10:10 -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 Mon, 13 Jan 2003 Volume: 10 Number: 4395
Today's topics:
Re: reading commandline parameters <barryk2@SPAM-KILLER.mts.net>
Regenerating Activeperl html documentation <stjm2@cam.ac.uk>
Re: Regenerating Activeperl html documentation (Tad McClellan)
Running a Word macro from Perl via OLE <nospam@nospam.com>
Re: search and replace problem <tassilo.parseval@post.rwth-aachen.de>
sleep aborts script <mdudley@execonn.com>
Re: sleep aborts script <nobull@mail.com>
Re: strange sort problem (Tad McClellan)
Re: strange sort problem <konny@waitrose.com>
Re: suggested revisions for the Posting Guidelines <nobull@mail.com>
Re: suggested revisions for the Posting Guidelines <nobull@mail.com>
Re: Suggestions for counter <bilkay@xxxlocalnet.com>
Re: Suggestions for counter <ubl@schaffhausen.de>
Re: Suggestions for counter (Tad McClellan)
Re: When does (pre|post)increment happen? (Peter J. Acklam)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 13 Jan 2003 08:24:55 -0600
From: Barry Kimelman <barryk2@SPAM-KILLER.mts.net>
Subject: Re: reading commandline parameters
Message-Id: <MPG.188c8833459e89429896cc@news.mts.net>
[This followup was posted to comp.lang.perl.misc and a copy was sent to
the cited author.]
In article <77mU9.648$0m4.142@read3.inet.fi>, Tommi (nomail@mail.com)
says...
>
> How can I read commandline parameters?
>
All parameters specified on the command line are stored in the array
"@ARGV"
To parse optional flags (i.e. those parameters that begin with a "-")
you can use the "use Getopt::Std;" module as follows :
%options = ( "d" => 0 , "c" => 0 , "s" => 0 , "S" => 0 , "t" => 0
,
"m" => 0 , "D" => 0 , "p" => 0 , "f"
=> 0 );
$status = getopts("DdftTspScmy:e:",\%options);
if ( !$status ) {
die("Usage : $0 [-dftTsScmp] [-e exclude_pattern] [-y year]
[pattern ... pattern]\n");
} # IF
--
---------
Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com
------------------------------
Date: Mon, 13 Jan 2003 15:31:38 -0000
From: "Stuart Moore" <stjm2@cam.ac.uk>
Subject: Regenerating Activeperl html documentation
Message-Id: <avum3n$2fg$1@pegasus.csx.cam.ac.uk>
Activestate perl comes with some rather nicely presented html documentation,
but there seems to be no way to get it to regenerate it other than partially
uninstall then reinstall. Anyone got any suggestions? Google gave nothing.
Stuart
------------------------------
Date: Mon, 13 Jan 2003 10:10:56 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Regenerating Activeperl html documentation
Message-Id: <slrnb25p8g.35c.tadmc@magna.augustmail.com>
Stuart Moore <stjm2@cam.ac.uk> wrote:
> Activestate perl comes with some rather nicely presented html documentation,
> but there seems to be no way to get it to regenerate it other than partially
> uninstall then reinstall. Anyone got any suggestions? Google gave nothing.
Find the actual *.pod files somewhere (even in a non-Windows distro).
Run them through pod2html.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 13 Jan 2003 16:48:59 +0000 (UTC)
From: "Vic Russell" <nospam@nospam.com>
Subject: Running a Word macro from Perl via OLE
Message-Id: <avuqlr$g1r$1@sparta.btinternet.com>
Hi,
Can anyone point me in the right direction here (or maybe tell me how to do
it)!
I want to run a Word97 VBA macro to carry out a task that I don't think I
can do directly via OLE. That is, find a string in a table cell and then
merge the cell above.
Anyway, I thought I might be able to do something like:-
$Word_file = $insWord->Documents->Open({FileName => $sWord_file_to_open});
$Word_file->{AttachedTemplate} = 'template_file_containing_macro.dot';
$insWord->Run("the_macro");
The attach seems to go OK but not the actual running of the macro. I'm not
sure whether attaching a template like this makes the macro available.
Any help here much appreciated.
Regards,
Vic Russell
------------------------------
Date: 13 Jan 2003 14:17:44 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: search and replace problem
Message-Id: <avuhq8$10g$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Urs Klingsporn:
> my @entry_keys;
> my %entry;
> my $mask;
>
> @entry_keys = keys(%entry);
> for(my $k = 0; $k < @entry_keys; $k++)
> {
> $mask = '§' . lc($entry_keys[$k]) . '§';
> $output =~ s/$mask/$entry{$entry_keys[$k]}/gimo;
> }
>
> it's part of a cgi script. i'm quit a newbie so...
>
> in short: all keys of %entry that occur in the string $output should
> be replaced with the value of the hash. it works for $k = 0 but there
> rest is just left as it is. what am i missing. I didn't found a
> solution so far...
Did you come up with this code yourself? If so, you probably have
misunderstood the meaning of the /o switch in regular expressions. From
perlop.pod:
[...] If you want such
a pattern to be compiled only once, add a "/o"
after the trailing delimiter. This avoids expen
sive run-time recompilations, and is useful when
the value you are interpolating won't change over
the life of the script. However, mentioning "/o"
constitutes a promise that you won't change the
variables in the pattern. If you change them,
Perl won't even notice. [...]
"is useful when the value you are interpolating won't change"
"If you change them, Perl won't even notice."
In essence, your substitution should look like:
$output =~ s/$mask/$entry{$entry_keys[$k]}/gimo;
Some other notes. The way you are iterating over the keys and values of
a hash is cumbersome. There's a much more elegant solution. Here's a
quick rewrite:
my %entry;
my $mask;
while (my ($key, $value) = each %entry) {
my $mask = '§' . lc($key) . '§';
$output =~ s/$mask/$value/gim;
}
Same could have been done using a for-loop:
for my $key (keys %entry) {
my $mask = '§' . lc($key) . '§';
$output =~ s/$mask/$entry{ $key }/gim;
}
The each() looks more suitable here.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Mon, 13 Jan 2003 10:23:22 -0500
From: Marshall Dudley <mdudley@execonn.com>
Subject: sleep aborts script
Message-Id: <3E22D9EA.1251663C@execonn.com>
I am having a problem where a sleep will abort the script and am unable
to figure out why. The code suppose to send an email out, then wait a
minute and send another email out. The browser connection is closed
before the sleep so that the browser does not "hang" for that time.
Here is the code:
close stdout;
sleep 10; #pause for 10 seconds
if (open(MAIL,"|\/usr\/sbin\/sendmail -t")) {
print MAIL "To: $in{'email'}\n";
print MAIL "Bcc: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: Welcome to $sc_cart_name [3]\n\n";
# print MAIL "\n\n"; #end the header
while ($line = <REPLY>) {
print MAIL $line;
}
}
close MAIL;
------------------------
If I comment out the sleep the second email gets sent, but if the sleep
is in the code as above, the second email never gets sent even when the
sleep is dropped to 10 seconds.
Anyone have any ideas why the script aborts on the sleep?
Thanks,
Marshall
------------------------------
Date: 13 Jan 2003 17:38:17 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: sleep aborts script
Message-Id: <u9lm1pj6gm.fsf@wcl-l.bham.ac.uk>
Marshall Dudley <mdudley@execonn.com> writes:
> I am having a problem where a sleep will abort the script and am unable
> to figure out why. The code suppose to send an email out, then wait a
> minute and send another email out. The browser connection is closed
> before the sleep so that the browser does not "hang" for that time.
"Browser"? Is this a stealth-CGI question? If so you presumably mean
"HTTP server" not "browser".
> close stdout;
> sleep 10; #pause for 10 seconds
> if (open(MAIL,"|\/usr\/sbin\/sendmail -t")) {
> If I comment out the sleep the second email gets sent, but if the sleep
> is in the code as above, the second email never gets sent even when the
> sleep is dropped to 10 seconds.
>
> Anyone have any ideas why the script aborts on the sleep?
I suspect what actually happens is caused to abort by some external
influence e.g. SIGPIPE a short time after you close STDOUT. If you
remove the sleep then you manage to send the mail before this happens.
I doubt that what you are observing has little to do with your
choice of Perl as a language in which to implement CGI scripts.
I suggest you fork your task completely into the background (see FAQ).
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Mon, 13 Jan 2003 07:16:27 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: strange sort problem
Message-Id: <slrnb25f1b.2ki.tadmc@magna.augustmail.com>
Mr I <konny@waitrose.com> wrote:
> @tmp = sort {$a->{NAME} cmp $b->{Name}} (@{$myval});
^^^^ ^^^^
^^^^ ^^^^
Case matters.
> <STDIN>;
Why are you reading, and then discarding, a line of input?
Was that just to get a pause during debugging or something?
> The problem is that I am running out of memeory during the sort.
A different followup has already addressed that problem.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 13 Jan 2003 16:40:08 +0000
From: Mr K <konny@waitrose.com>
Subject: Re: strange sort problem
Message-Id: <02ruva.s4b1.ln@leon.amaretti.net>
thank you both,
indeed should have ask perl first...
if i had slept i would have not posted this.
but thanks for the help.
Tad McClellan wrote:
> Mr I wrote:
>
>
> > @tmp = sort {$a->{NAME} cmp $b->{Name}} (@{$myval});
>
> ^^^^ ^^^^
> ^^^^ ^^^^
> Case matters.
>
>
>
> > ;
>
>
>
> Why are you reading, and then discarding, a line of input?
>
> Was that just to get a pause during debugging or something?
>
>
>
> >The problem is that I am running out of memeory during the sort.
>
>
>
> A different followup has already addressed that problem.
>
>
------------------------------
Date: 13 Jan 2003 18:06:34 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: suggested revisions for the Posting Guidelines
Message-Id: <u9hecckjpx.fsf@wcl-l.bham.ac.uk>
guyw@multiline.com.au (Guy Worthington) writes:
> [snipped two examples of the definition lurk]
Reinstated - because they are relevant to give context...
Current version based on words from Godzilla:
Lurk for a while before posting
This is very important and is expected regardless of what
newsgroup you are visiting. Lurking means to simply monitor a
newsgroup for a period of time until you become very familiar
with local customs. Think of a newsgroup as foreign
culture. Each newsgroup has its own specific customs and
rituals. Get to know those customs and rituals well before you
participate. This will help you to avoid embarrassing social
situations. Consider yourself to be a foreigner at first!
(78 words)
Could, without significant loss of information, be reduced to:
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!
(50 words)
> Tad McClellan wrote:
>
> > I'm not seeing how [the rewrite of the definition ] has been made less
> > pleasant.
>
> > Please elaborate.
>
> I think it's important, if you're going to teach someone a life lesson
> (such as the way they communicate), that it be done with humour.
I honestly can't see how there is any more humour in the first version
than the second.
> > I'm not seeing [that the rewritten definition is an open invitation
> > to be rude]
>
> Now you're just being obtuse.
Perhaps we're all being obtuse, I really can't see how anyone could
justify any act rudeness by the second but not the first. Can you
explain?
Elsewhere in this thread guyw@multiline.com.au (Guy Worthington)
writes:
> The original definition was pleasant
That's a very subjective view. I think both versions are a little
patronising. Mine a little less so.
> and easy to read.
I'm dyslexic so my mind works differently. I've observed over the
years that non-dyslexics actually find prose bulked-out with redundant
words added easier to read than prose in which every word carries
meaning[1]. As a dyslexic I definitely find prose in which every word
carries meaning easier to read.
[1] My personal theory to explain this is that the human brain employs
a form of piplelining while processing language. People are used to
reading prose with redundancy so they habitually run the visual end of
their reading pipline faster than their concious mind could actually
cope with comprehending all those words. They rely on the fact that
early stages of their language processing operations will filter out
the noise.
------------------------------
Date: 13 Jan 2003 18:30:19 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: suggested revisions for the Posting Guidelines
Message-Id: <u9d6n0kimc.fsf@wcl-l.bham.ac.uk>
tadmc@augustmail.com (Tad McClellan) writes:
> > Do you (by which I mean the nettizens as of clp* as a whole, not just
> > Tad) want me to go though the whole document to find other stuff like
> > this or do people prefer the more wordy style?
>
>
> I'd like that. I prefer terseness.
OK applying the same tightening to some of the other metainformation pragraphs...
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 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.
Once we get into the main body of the document the wording is fairly
tight already. I could maybe squeeze out 5% but I don't think it's
warranted.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Mon, 13 Jan 2003 09:14:05 -0500
From: "Bill K." <bilkay@xxxlocalnet.com>
Subject: Re: Suggestions for counter
Message-Id: <20030113.091402.392035568.19008@xxxlocalnet.com>
In article <kVoU9.8477$WT3.6813@news.bellsouth.net>, "Brett"
<bbsouth@bellsouth.net> wrote:
> I've tried a few different counters but can't find one that is easy to
> setup. I'd like one that is less than 50k on the webpage, easy to setup
> and doesn't require going out to get various modules, such as FLY. I'm
> not very Perl savy but can setup a counter if it doesn't require
> compiling additional modules (FLY). Does any one have suggestions on a
> webpage counter that is self contained? Meaning, a small program that
> includes all the files necessary to run in either .cgi or .pl format.
>
> I almost got this one giong:
> http://www.muquit.com/muquit/software/Count/Count.html. It is running
> on my local machine with Win2k Pro and IIS5. For some reason, I get a
> file not found on the remote machine running Win2k Server. I rename the
> executable from count.exe to count.old and the browser tries to download
> it. That verifies the file is there. Something is wrong with permissions
> probably but I can't figure it out. IIS has executable on the cgi-bin
> folder and in Windows Explorer has IUSER with executable on the cgi-bin
> folder.
>
> If some one could make suggestions on how I can get Count running, I'd
> be thrilled. The count.exe file is 100k so I'd rather find something
> smaller but would like to know why Count doesn't work.
>
> Running:
> Win2k Server
> IIS5
>
> Thanks,
> Brett
Here's one I wrote for myself. It only outputs text, though, and my
programming probably sucks, but it is easy to set up. All you need is a
file to keep the data in. It consists of a single line for each file to
track, each line split into four colon-separated fields:
[0] Page name (REQUEST_URI)
[1] hitcount1 (this number will be output if [3] is set)
[2] hitcount2 (this isn't output, you can use it to keep track of daily,
weekly, etc., hits)
[3] 1 if you want the count output to page, 0 if not.
Change "path_to_data_file" to the appropriate value.
If you're foolish enough to use this program, I'm not responsible for the
results.
#!/usr/bin/perl
#
# Store and increment hit counts for various files.
#
$dfile = {path_to_data_file} ;
$refpage = "$ENV{'REQUEST_URI'}" ;
open(INFO, "$dfile") || &error(1) ;
@hcount = <INFO> ;
close(INFO) || &error(2) ;
$pagefound = false ;
for ($i = 0; $i <= $#hcount; ++$i)
{
@listpage = split(/:/, $hcount[$i]) ;
if ( "$listpage[0]" eq "$refpage" )
{
@thispage = @listpage ;
++$thispage[1] ;
++$thispage[2] ;
$hcount[$i] = "$thispage[0]:$thispage[1]:$thispage[2]:$thispage[3]" ;
$pagefound = true ;
}
}
if ( $pagefound ne true ) {
exit ;
}
open(INFO, ">$dfile") || &error(3) ;
print INFO @hcount ;
close(INFO) || &error(4) ;
if ( $thispage[3] == 1 )
{
print "Content-type: text/html\n\n";
print "$thispage[1]\n" ;
}
exit ;
sub error
{
local($a) = (0 - $_[0]);
print "Content-type: text/html\n\n";
print "$a\n" ;
exit ;
}
------------------------------
Date: Mon, 13 Jan 2003 15:30:43 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Suggestions for counter
Message-Id: <avulqp$49n$1@news.dtag.de>
Bill K. wrote:
> Here's one I wrote for myself. It only outputs text, though, and my
> programming probably sucks
Yes it does. You are not serious about this, are you?
->malte
--
srand 108641088; print chr int rand 256 for qw<J A P H>
------------------------------
Date: Mon, 13 Jan 2003 09:02:28 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Suggestions for counter
Message-Id: <slrnb25l84.2s9.tadmc@magna.augustmail.com>
Bill K. <bilkay@xxxlocalnet.com> wrote:
> In article <kVoU9.8477$WT3.6813@news.bellsouth.net>, "Brett"
><bbsouth@bellsouth.net> wrote:
>
>> I've tried a few different counters but can't find one that is easy to
>> setup.
I'd recommend seeing what you can find at:
http://nms-cgi.sourceforge.net/
> If you're foolish enough to use this program, I'm not responsible for the
> results.
Brett should pay particular attention to that part...
> #!/usr/bin/perl
The first clue as to the quality of the code is right here.
If you find code that does not have warnings and strict enabled,
discard it and keep looking.
> open(INFO, "$dfile") || &error(1) ;
^ ^
^ ^
A useless use of double quotes.
open(INFO, $dfile) || &error(1) ; # does the same thing
From Perl FAQ 4:
What's wrong with always quoting "$vars"?
> @hcount = <INFO> ;
> close(INFO) || &error(2) ;
While the other things are merely "indicators" that you shouldn't
use this code, here is a complete deal-killer.
It does not implement file locking, which is required in a
multi-tasking environment such as CGI.
The count will become corrupted.
If you're not going to do file locking, you might as well call
rand() and save that number as the count.
> sub error
> {
> local($a) = (0 - $_[0]);
There is another indicator of poor quality code, namely using
local() when my() will do.
You should always prefer my() variables over local() variables,
except when you can't.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 13 Jan 2003 19:42:21 +0100
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: When does (pre|post)increment happen?
Message-Id: <adi499iq.fsf@online.no>
Brian McCauley <nobull@mail.com> wrote:
> pjacklam@online.no (Peter J. Acklam) writes:
>
> > Subject: When does (pre|post)increment happen?
>
> The increment happens at the time the (pre|post)increment
> subexpression is evaluated. It is _not_ pre- or post- the
> whole expression that contains it. [...]
Thank you very much for the explanation! I got it! :-)
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
------------------------------
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 4395
***************************************