[8965] in Perl-Users-Digest
Perl-Users Digest, Issue: 2583 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 13 14:10:29 1998
Date: Wed, 13 May 98 11:01:42 -0700
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, 13 May 1998 Volume: 8 Number: 2583
Today's topics:
probs with OLE in Perl, help please <jhedy@racingschools.com>
Re: Question: Finding which element of a list a string (Jim Allenspach)
Re: Randomly sorting an array <rootbeer@teleport.com>
Re: Recursive find <merlyn@stonehenge.com>
Re: Regular Expression Question (Craig Berry)
Re: Significant digit? <xuming@xxx.email.unc.edu>
Re: Significant digit? <rra@stanford.edu>
Re: Tip: Filehandles <rootbeer@teleport.com>
user "nobody"? (*/chebs )
Where to put the my <frankie@etsetb.upc.es>
Re: Where to put the my (Craig Berry)
Re: Where to put the my (Andy Lester)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 13 May 1998 08:29:42 -0700
From: "John Hedy" <jhedy@racingschools.com>
Subject: probs with OLE in Perl, help please
Message-Id: <895073463.795620@slave2.aa.net>
I wrote a simple PERL script using your example and tried to run it
from IIS 4. However, the script just hangs and never returns control back
to the browser. When I single step thru the script with a PERL debugger,
it looks like the component calls are working as expected and the
scripts completes successfully with the expected results. The strange
part is if I use _step_ the script works, if I use _next_ or _continue_
after a certain point, the script hangs as in the browser. I don't see
why. Can anyone help? I had PERL for Win32 build 315 with CGI.pm and
ODBC.pm installed. Didn't work with that although I had read a
comment saying that Perl 316 might have addressed memory leak problems with
the OLE component. I downloaded and installed PERL for Win32 build 316 .
Same results.
I am attaching my code below. Any assistance you can provide would be
much appreciated. Thanks in advance!
#!/usr/bin/perl -- -*-perl-*-
# testauth.pl
use CGI qw(:all);
use OLE;
print header;
print start_html(-BGCOLOR=>'#FFFFFF');
print "SCRIPT_NAME is $ENV{SCRIPT_NAME}<BR>";
print "Server_Name is $ENV{SERVER_NAME} <BR>";
print "HTTP_AUTHORIZATION is $ENV{HTTP_AUTHORIZATION}<BR>";
$user = getUser();
print "user is $user <BR>";
print end_html;
exit;
sub getUser {
$authx = CreateObject OLE "AUTHXOCX.AuthXOCXCtrl.1";
$userid = $authx->CurrentUserName($ENV{SERVER_NAME},
$ENV{SCRIPT_NAME}, $ENV{HTTP_AUTHORIZATION});
undef $authx;
return ($userid);
}
I've been able to successfully write an ASP script that calls the OCX
component successfully. If nobody can determine what is wrong above, does
anyone have an example of a PERL script calling an ASP that then returns
control and parameters back to the PERL script?
Something else of interest to note:
I added a couple more statements in my script -
$authx->DESTROY;
OLE->DESTROY;
(where $authx was the object I created using CreateObject OLE...) . Now,
in the debugger I _sometimes_ see an error:
"Attempt to free unreferenced scalar during global destruction.
OLE::DESTROY called at testauth.pl line 0
eval {...} called at testauth.pl line 0"
I noticed that even after I had explicitly called OLE->DESTROY and
$authx->DESTROY, the process tried to call the OLE->DESTROY function
immediately after the exit 0; in my script. So it seems like a clean up
process is _always_ initiated at the end of execution anytime an OLE object
is created. Because my script had already completed that by calling it
explicitly from the program, the process could not find anything to
"destroy" . The question is, why was the script then hanging when I hadn't
called the OLE->DESTROY from my program? It does look like a memory problem
to me.
Can anyone help? Assistance is much appreciated.
------------------------------
Date: 13 May 1998 11:00:43 -0500
From: jima@MCS.COM (Jim Allenspach)
Subject: Re: Question: Finding which element of a list a string corilates to
Message-Id: <6jcg3b$jka@Venus.mcs.net>
>>>I'm trying to find out what position a given string holds in a list
>>
>> You might check the Perl FAQ (http://language.perl.com/faq/)....
>I just (re-)read the FAQ and, as its title states, it tells *whether*
>... But the original question was *where*.
Aha! Let me escape through the back door of that "might" in my
posting...
>Is there an answer to this question better than the obvious and
>mundane -- count up a loop?
Hey, what's wrong with obvious and mundane? If it works, it works.
(And let's not forget that people who maintain your code might themselves
be obvious and mundane .-)
But anyway, apart from the loop answer. If you're reading in the
array data in your program, you can adapt the idea in the FAQ of
inverting the array:
> for ('however','you','get','your','data') {
> push(@array,$_);
> $array_index{$_} = $#months;
> }
Then you could just do a simple lookup in the %array_index hash, to see
where your item is:
> $where = $array_index{$element};
> if (defined $where) {
> print "$element is at $where\n"
> } else {
> print "$element isn't in the array\n"
> }
jma
------------------------------
Date: Wed, 13 May 1998 16:59:42 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Kjell Arne Rekaa <etoxkar@eto.ericsson.se>
Subject: Re: Randomly sorting an array
Message-Id: <Pine.GSO.3.96.980513095906.21974p-100000@user2.teleport.com>
On Wed, 13 May 1998, Kjell Arne Rekaa wrote:
> > > for my $i (1..$#list) { # Yes, start at 1!
> The "my" before "$i" generates compilation error
Not on a recent version of Perl. Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 13 May 1998 17:53:54 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
To: Jamie Hoglund <jhoglund@mirage.skypoint.net>
Subject: Re: Recursive find
Message-Id: <8cd8dioy4s.fsf@gadget.cscaper.com>
>>>>> "Jamie" == Jamie Hoglund <jhoglund@mirage.skypoint.net> writes:
Jamie> but if you're going to program it yourself..
.. you should do it correctly.
Jamie> if(-d $dir){
And since you didn't check -l here, you will chase symlinks...
Jamie> chdir("..");
Meaning that this will fail, or end you up in a very different directory.
Please, please, PLEASE.
Do *NOT* reinvent this code. File::Find comes with every modern
version of Perl.
Do *NOT* reinvent this code, unless you understand ALL the problems
that have been solved using the *current* code.
Do *NOT* reinvent this code.
Am I making myself clear?
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 110 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 13 May 1998 17:15:06 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Regular Expression Question
Message-Id: <6jcker$os7$1@marina.cinenet.net>
Aidan Rogers (aidan@crux.blackstar.co.uk) wrote:
: is it possible to match from the beginning of the line (the ^) right up
: to a specified character? e.g.
:
: Davy "Biscuit" Beattie (DB)
:
: I want to match everything from the start of the line, up to the (
: and put it into $1.
Sure, why not? You already know that ^ is 'beginning-of-line,' and
presumably that . is 'any character.' The only tricky part is matching
up to the *first* left-paren, and non-greedy matching takes care of that.
And actually, since you want everything before the first left paren, you
don't even really need to beginning-of-line anchor it.
So, if you want to match up to and including the first '(', use:
($match) = $string =~ /(.*?\()/;
Or, if you want to exclude the '(', use:
($match) = $string =~ /(.*?)\(/;
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Wed, 13 May 1998 11:13:30 -0400
From: xuming wang <xuming@xxx.email.unc.edu>
Subject: Re: Significant digit?
Message-Id: <3559B89A.7643D4E8@xxx.email.unc.edu>
Craig Berry wrote:
>
> John Stanley (stanley@skyking.OCE.ORST.EDU) wrote:
> : In article <6jalpa$pei$2@client2.news.psi.net>,
> : Abigail <abigail@fnx.com> wrote:
> : >1200 is 4 significant digits. Try:
> :
> : 1200 has 2 significant digits. 1200. has 4.
>
> It's actually impossible to say how many either has a priori, though the
> latter does more strongly suggest 4. Abigail's correct in pointing out
> that only exponential notation is unambiguous.
I am a Chemist (well, Biochemist), and read tens of scientific papers every
week. I've never seen something like 1200. (with point) and AFAIK, 1200 has 4
significant digits. we have to write it in scientific notation if there's only
2 significant digits: 1.2e3.
I think the subroutine I posted to cpl.module is pretty simple and works, but I
am new to perl so probably there is something I missed.
sub sigfig {
my ($num, $sd) = @_;
return 0 if $num == 0;
/([1-9]\d*)\.?(\d*)/ and $sd > length ($1 . $2)
and $sd = length ($1 . $2);
# shouldn't add more significant digits than it has.
sprintf "%1.*e", $sd - 1, $num;
}
but I really don't know how should I deal with something like 0.00, how many
siginificant digits it has?
this sub always returns number in scientific notation and it will round.
--
Xuming Wang
To reply via email, remove xxx from address.
------------------------------
Date: 13 May 1998 10:48:35 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Significant digit?
Message-Id: <m3yaw6qcy4.fsf@windlord.Stanford.EDU>
xuming wang <xuming@xxx.email.unc.edu> writes:
> I am a Chemist (well, Biochemist), and read tens of scientific papers
> every week. I've never seen something like 1200. (with point) and
> AFAIK, 1200 has 4 significant digits.
Um, no. Trailing zeroes are only considered significant if they occur to
the right of the decimal place. 1200 has two significant figures, while
1.200e3 has four significant figures.
> we have to write it in scientific notation if there's only 2 significant
> digits: 1.2e3.
That's definitely standard practice in the sciences, yup.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Wed, 13 May 1998 17:39:29 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Jamie Hoglund <jhoglund@mirage.skypoint.net>
Subject: Re: Tip: Filehandles
Message-Id: <Pine.GSO.3.96.980513103807.21974r-100000@user2.teleport.com>
On 13 May 1998, Jamie Hoglund wrote:
> Seriously, what is wrong with using globs?
Like anything else, there's nothing wrong if you're using them properly.
But typeglobs are often misunderstood and misused. Alas!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 13 May 1998 17:12:06 GMT
From: chebs@elfin.org (*/chebs )
Subject: user "nobody"?
Message-Id: <355fd463.30737166@news.demon.co.uk>
Hi
I would like to write a script to check if a my chat server is
still running and if not start it up again.
I have been experimenting with:
$pscheck = `ps -ef |grep chebs`;
if($pscheck =~ /chatServer/i){
$start = `java chatServer &`;
}
Is there any way to start the process with my 'login' as id
instead of 'nobody' when calling the script from a browser?
or is that a bad idea?
If it's better to use 'cron' to run the script would it run
as 'me' or 'nobody'?
Many thanks
chebs
------------------------------
Date: Wed, 13 May 1998 18:38:38 +0200
From: Francesc Guasch <frankie@etsetb.upc.es>
Subject: Where to put the my
Message-Id: <3559CC8E.F4E8BBFB@etsetb.upc.es>
Hi, If I have code like this:
while (thingie) {
my $var=stuff
}
does it creates an instance of $var everytime ?
Should it be better do the my before ?
my $var;
while (thingie) {
$var=stuff
}
Just wondering
--
^-^.-----, mailto:frankie@etsetb.upc.es
o o _ ) http://www.etsetb.upc.es/~frankie
Y (_, (__(Ssss
------------------------------
Date: 13 May 1998 17:40:25 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Where to put the my
Message-Id: <6jclu9$os7$2@marina.cinenet.net>
Francesc Guasch (frankie@etsetb.upc.es) wrote:
: Hi, If I have code like this:
:
: while (thingie) {
: my $var=stuff
: }
:
: does it creates an instance of $var everytime ?
Yes, or at least it acts that way. (Not going to make any
statements about how it's implemented internally; I don't
know.)
: Should it be better do the my before ?
:
: my $var;
: while (thingie) {
: $var=stuff
: }
Let's ask Mr. Benchmark...
#!/usr/bin/perl -w
# mytest.pl -- test my overhead inside/outside loop.
# Craig Berry (19980513)
use strict;
use Benchmark;
timethese(10000, {
outside => 'my $foo; for (1..100) { $foo = $_ }',
inside => 'for (1..100) { my $foo = $_ }'
});
Results:
Benchmark: timing 10000 iterations of inside, outside...
inside: 53 secs (36.16 usr 0.00 sys = 36.16 cpu)
outside: 29 secs (26.32 usr 0.02 sys = 26.34 cpu)
It appears having the my declaration outside the loop produces
significantly faster code.
Of course, issues of style (and perhaps reference-use, need to
think about that a bit) may argue for using my inside the loop
instead, since the difference will be tiny for all but the
highest-iteration-count loops.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 13 May 1998 17:49:37 GMT
From: petdance@maxx.mc.net (Andy Lester)
Subject: Re: Where to put the my
Message-Id: <6jcmfh$fdh$1@supernews.com>
: while (thingie) {
: my $var=stuff
: }
: does it creates an instance of $var everytime ?
Yes.
: Should it be better do the my before ?
Define "better". If you're counting milliseconds, it might be. However,
I'd far rather have a more readable, less breakable piece of code than one
that runs insignificantly faster.
Premature optimization is the root of all evil.
xoxo,
Andy
--
--
Andy Lester: <andy@petdance.com> http://tezcat.com/~andy/
Chicago Shows List: <shows@ChicagoMusic.com> http://ChicagoMusic.com/
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 2583
**************************************