[13426] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 836 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 17 22:07:17 1999

Date: Fri, 17 Sep 1999 19:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <937620309-v9-i836@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 17 Sep 1999     Volume: 9 Number: 836

Today's topics:
        $ENV{'REMOTE_USER'}; under Win32 <barm@aarmstrong.fsbusiness.co.uk>
    Re: $ENV{'REMOTE_USER'}; under Win32 (Kragen Sitaker)
    Re: A New Resource <cassell@mail.cor.epa.gov>
        Can Perl interface a compiled C program and a web site  (Jim)
    Re: Case insensitive SQL query <cassell@mail.cor.epa.gov>
        Checking for Modules in Perl <2bunnyhop@home.com>
    Re: Database retrieval of information using PERL <cassell@mail.cor.epa.gov>
    Re: Encrypting (and decrypting) password <ehpoole@ingress.com>
        Help on Perl/Cgi script <byuan@eee.hku.hk>
        How do I print Array of hash? (nation)
    Re: How do I print Array of hash? <rick.delaney@home.com>
    Re: how to do this? <cassell@mail.cor.epa.gov>
    Re: How to split HTML text ? <cassell@mail.cor.epa.gov>
    Re: How to split HTML text ? (Kragen Sitaker)
    Re: How to test for file Perl <resource@ERASEjps.net>
    Re: How to test for file Perl <uri@sysarch.com>
    Re: Lambda calculus stuff in Perl (Kragen Sitaker)
    Re: Line chart (Abigail)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 18 Sep 1999 01:20:04 +0100
From: "Andrew Armstrong" <barm@aarmstrong.fsbusiness.co.uk>
Subject: $ENV{'REMOTE_USER'}; under Win32
Message-Id: <7rulso$r6f$1@news7.svr.pol.co.uk>

Does anyone know what the win32 equivalent of remote_user is ?
I know that it may not be possible but is there any way of identifying the
user from their login (either from a network or from the profile they are
logged in under).

Thanks




------------------------------

Date: Sat, 18 Sep 1999 00:57:44 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: $ENV{'REMOTE_USER'}; under Win32
Message-Id: <csBE3.17559$N77.1290521@typ11.nn.bcandid.com>

In article <7rulso$r6f$1@news7.svr.pol.co.uk>,
Andrew Armstrong <barm@aarmstrong.fsbusiness.co.uk> wrote:
>Does anyone know what the win32 equivalent of remote_user is ?

REMOTE_USER.

>I know that it may not be possible but is there any way of identifying the
>user from their login (either from a network or from the profile they are
>logged in under).

REMOTE_USER doesn't do this under Unix, let alone under Win32.  You can
try using ident.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Fri Sep 17 1999
52 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: Fri, 17 Sep 1999 17:40:57 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: A New Resource
Message-Id: <37E2DF99.EA782F7F@mail.cor.epa.gov>

Elaine -HFB- Ashton wrote:
> 
> Scott Gray wrote:
> > Tutorials:PERL,CGI,JavaScript,DHTML,Unix,SQL, more...
> > Hosting:CGI, ASP,PHP,Mod_Perl,JServ,C++,SSI,e-commerce,more...
> 
> Oh lord, the "C" word is everywhere on that site.
> 
> /me heads for the hills before the riotous din becomes unbearable.

Even worse, you can't even get in there unless you turn
JavaScript on first.  Yuck.

Who wants a JavaScript tutorial on Perl?

What next, a COBOL-based tutorial on Eiffel?

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


------------------------------

Date: Fri, 17 Sep 1999 21:35:14 -0500
From: jkrogerDONCHA_SPAM_ME@earthlink.net (Jim)
Subject: Can Perl interface a compiled C program and a web site in HTML?
Message-Id: <jkrogerDONCHA_SPAM_ME-1709992135140001@ip58.princeton.nj.pub-ip.psi.net>

I have a large C program I'd like to connect to a web site for users to execute.
I don't know how to start. Can I use Perl?

Thanks
Jim



------------------------------

Date: Fri, 17 Sep 1999 17:45:08 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Case insensitive SQL query
Message-Id: <37E2E094.DF9BFD72@mail.cor.epa.gov>

mrbog@my-deja.com wrote:
[snip of blather]
> > >YES, I DO, because there are 2400 people to answer them.
> >
> > More like a couple dozen.  And they're here to help answer questions
> > about Perl.  Why make busy-work for them?  They're doing a nice thing
> > for us.  It's only fair to avoid making extra demands.
> 
> couple dozen?! Try a couple thousand.  The more people posting
> questions, the more people there are to answer them.

Hardly.  If you knew enough Perl you would notice that many of
the people who only drop in to ask one question and stick around 
to answer one to three others, give the WRONG answers!  So
then the 'couple dozen' not only have to answer those same
questions, but have to go back and fix the wrong answers,
pointing out why they were not good things to tell people to do.

Look at the weekly stats from Greg Bacon and see who answers
how many questions.  It is dangerously close to 'a couple
dozen' some weeks.

> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.

Of course.  deja.com
"Share what you don't know is wrong. 
 Learn what you can't be bothered to verify."
 
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


------------------------------

Date: Sat, 18 Sep 1999 01:19:01 GMT
From: "Craig Vincent" <2bunnyhop@home.com>
Subject: Checking for Modules in Perl
Message-Id: <9MBE3.41407$kL1.499323@news2.rdc1.on.home.com>

Is there a way to have Perl check to see if particular modules are installed
without doing an exist check in the standard library directories?

Craig Vincent




------------------------------

Date: Fri, 17 Sep 1999 17:17:11 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Database retrieval of information using PERL
Message-Id: <37E2DA07.7A108B2F@mail.cor.epa.gov>

Steve Klein wrote:
> 
> Does anyone know of a good script or an example of a PERL program that takes
> database information and does a Query on the info.

Well, for Perl you can look at all the examples in the docs
for the DBI and DBD::* modules.

> Example:  there would be a form giving input areas for addresses and based
> on that address, the certain field would have the correct zip-code.  The
> goal from the form is the person fills out their address, and the CGI will
> lookup that address, see if it falls between a certain criteria, and then
> give back the appropriate zip-code.

There are a couple tutorials accessible from the search
facility at www.perl.com which hit on DBI and CGI at
the same time.  At least one of these ought to have what
you're looking for.

HTH,
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


------------------------------

Date: Fri, 17 Sep 1999 20:45:45 -0400
From: "Ethan H. Poole" <ehpoole@ingress.com>
Subject: Re: Encrypting (and decrypting) password
Message-Id: <37E2E0B9.BF23E68@ingress.com>

Steve Button wrote:
> 
> >For simple encryption (and there isn't much point to anything more complex
> >if you are still passing everything cleartext including the initial
> >login), you could use XOR encryption -- and making certain the key
> >contained in the script's code does not become compromised.
> 
> Yes, that's what I want to do!  (for now) I assume you're suggeting that I
> simply XOR each of the characters with some (known) bitmask and then do the
> same thing again at the other end, to switch it back again. This sounds like
> what I need.  I don't need anything more fancy than that, because I'm only
> giving people the ability to advertise property for sale / rent for free.
> The worst thing that could happen is that someone tampers around with the
> information on there.  Is someone really going to bother doing this, when I
> am giving them the ability to put whatever they want under their own account
> anyway?  I can see that it would be fairly trivial for someone to crack this
> by simply XORing with all 255 possible combinations and seeing which one
> comes up with a word (or trying each one in turn). But, it's a lot better
> than nothing !!

You can do this on the server side.  Later on you sound like you are
talking about trying to implement this on the client side which would not
make much sense  Accept that you are passing everything around in
plaintext and let the server do the encrypting/decrypting.  To try and do
this on the client (browser) side would require the use of JavaScript and
essentially nullify the value of the encryption altogether JavaScript is
not universally enabled/available.  Further, trying to encrypt browser
side means the browser will have the very key necessary to decrypt, thus
erasing your limited 'nuisance' resistance.  You don't have much security,
but passing around a subsequent sessionid in an encrypted manner and
instructing the browser not to cache the login page can help prevent
'looking over the shoulder' type theft.  

You are not limited to an 8 bit XOR encryption function.  You can create
an encryption key of most any length (though sticking to multiples of 8
bits will make your life simpler for obvious reasons).  You then
encode/decode the string in blocks of however many bits/bytes your key
is.  So a 40-bit key (5 bytes) would process 5 bytes of the string at a
time, strings less than 5 bytes are padded with a known character to be
chopped off during the decode routine (or you can store the length of the
string and truncate anything beyond that length).  To improve security,
you can add the value of a corresponding byte (from the private unencoded
string) from the previous block and add it to the current key byte
(assuming you XOR the data block and the key block one byte at a time) and
take the modulus of the two and XOR that with the data byte.  This makes
each block a partial product of the previous block and helps reduce the
chance that a dictionary attack will prove fruitful (if you truly do
independent blocks then it becomes fairly trivial to observe patterns in a
data stream of sufficient length or blocks with sufficiently little
entropy).

> >
> >However, you had better make certain that there is some random data (but
> 
> So, you mean that I should (for example) hold a table of 24 different
> characters (keys) and use a different one depending upon the hour?
> (obviously I will NOT do this now, as someone would just have to read this
> post.....)

You could do something such as that.  One simple method would be to take
the value of time() (i.e. seconds since 1970) and subtracting (or adding)
some arbitrary value to it.  The actual arbitrary value is stored in your
script, and, if the script is properly secured, is likely 'secure enough'
for what you propose (e.g. a scenerio where there is a little value to a
break-in and worst-case damage would be embarassment with little or no
financial risk at stake).  By decoding this value and adding back your
'correction factor' you can add simple expiratory capability to your
script (expire a sessionid which has been idle for a period of time).

Now, if we were discussing the storage of 'sensitive' data, such as credit
card info, you would want to use (at a minimum) a public-key encryption
method.  The script would encode everything with its stored public key
while you retain the private key in a secure location and supply it to the
script only when you have a screen that needs to have the data decrypted.
> >
> >If you are looking for genuine encryption and not just something that
> >makes life a tiny bit more complicated to ward off crackers you should be
> >using SSL and allowing the client and server to handle encrypting the
> >entire data stream.
> 
> Hmmmmmm. But that alone would not solve my initail problem would it?  I
> mean, if I just passed the password in the POST method (or whatever it is)
> they would get their OWN password printed in plain text at the top of their
> screeen in the box that says "location:".  This would give the perception of
> bad security.

If your login page is done using the POST method (and not the GET method),
the username and password will not be passed as part of the URL, they will
be passed to the 'login' portion of your script via STDIN.  It would then
be the responsibility of your 'login' subroutine to send back a
redirection header ("Location: http://....?session=143243223\n\n")
containing the full URL plus the encrypted sessionid you wish to store.

-- 
Ethan H. Poole           ****   BUSINESS   ****
ehpoole@ingress.com      ==Interact2Day, Inc.==
(personal)               http://www.interact2day.com/


------------------------------

Date: Sat, 18 Sep 1999 09:48:15 +0800
From: byuan <byuan@eee.hku.hk>
Subject: Help on Perl/Cgi script
Message-Id: <37E2EF5F.6C3D2F68@eee.hku.hk>

Hi, all:

Perl is a new tool for me, who can tell me where I can download some
free Perl /CGI script so that
I can test it in my web server?

I want to build a remote server, i.e. web users can run our Fortran/C
application through Internet,
but I do not know how to write the Perl/CGI script in the server side,
anyone can help me?

thanks in advance.


Yuan Bin
byuan@eee.hku.hk




------------------------------

Date: Sat, 18 Sep 1999 00:14:52 GMT
From: martyr160@yahoo.com (nation)
Subject: How do I print Array of hash?
Message-Id: <37e2d714.10703517@news.pdq.net>

I'm new to Perl and am completely confused on how to print the records
in this type of variable.  I need to print the records in a
subroutine.  Any help would be very appreciated

my $testvar = ['Some', 'data', 'is', 'here', 
            ['an', 'array', 'of', {hash => 'yes', array => 'no'}, 0,
1], 
            {how => 'do', I => ()}, [{}]];


sub itemCount
{
	foreach(@_)
	{
		if (ref $_ eq "ARRAY" || ref $_ eq "HASH")
		{
			
			for $i (0 .. $#_)
			{
				# Not sure what to do from here.
				#  $_ turns out to be equal to 
				#  -1 so I never can get farther
				# than this.  Not sure what I need
				# to do in here either
			}
		}
		else
		{
			print "\n$_.\n";
		}	
	}
}



------------------------------

Date: Sat, 18 Sep 1999 01:17:54 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: How do I print Array of hash?
Message-Id: <37E2E83C.110949FE@home.com>

[posted & mailed]

nation wrote:
> 
> I'm new to Perl and am completely confused on how to print the records
> in this type of variable.  I need to print the records in a
> subroutine.  Any help would be very appreciated
> 
> my $testvar = ['Some', 'data', 'is', 'here',
>             ['an', 'array', 'of', {hash => 'yes', array => 'no'}, 0,
> 1],
>             {how => 'do', I => ()}, [{}]];

If you just want to print them to examine them then try Data::Dumper.

    use Data::Dumper;
    print Dumper($testvar);

perldoc Data::Dumper

If you want to do your own formatting then check out perldsc which shows
how to create and print complex data structures.

-- 
Rick Delaney
rick.delaney@home.com


------------------------------

Date: Fri, 17 Sep 1999 17:30:01 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: how to do this?
Message-Id: <37E2DD09.C9A848F8@mail.cor.epa.gov>

Lovenox wrote:
> 
>   Is there a novice perl forum that addresses simple stuff such as how to
> change variables, chmod to 755, configure the program, etc?  Basically learn
> how to set up Perl scripts in the right directories so they actually work.
> Can a good FTP program do all this?  The freeware isn't very helpful as far
> as FTP clients go.

I haven't seen such a forum.  But there are web tutorials which
walk you through the basics.  Try the search facility at
www.perl.com and look up 'tutorial'.  That should get you started.

HTH,
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


------------------------------

Date: Fri, 17 Sep 1999 17:21:54 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: How to split HTML text ?
Message-Id: <37E2DB22.1FE2E695@mail.cor.epa.gov>

Choi Jin-Ho wrote:
> 
> I'm developing a simple medicel English --> Korean
> HTML document translation script.
> 
> The concept is very simple. Split line into words, and
> replace english words with appropriate korean words.
> Grammar is just ignored (so it is simple ...).

But won't that make parts of it unreadable?  You know
how annoyingly complicated English is.  How do you
handle English words which mean different things de-
pending on whether they are nouns, verbs, adjectives...
Or words which mean different things in English and
in medical jargon?
 
> I want to do like this :
> 
> INPUT :
> 
> $line = '<p>You can find at<a href =
> "http://www.yahoo.com">Yahoo</a>';

I would recommend using HTML::Parser and following
the guidelines in the docs.  Kragen gave you a nice
regex answer, but he knows from experience where to use
that and where *not* to.  Regexes break in a variety
of icky ways on real-world HTML.  Read the FAQ for a
few common examples.

P.S.  Abigail will probably tell you that HTML::Parser
does a less-than-ideal job of parsing HTML.  But nothing's
perfect.

HTH,
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


------------------------------

Date: Sat, 18 Sep 1999 00:52:20 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: How to split HTML text ?
Message-Id: <8nBE3.17533$N77.1289696@typ11.nn.bcandid.com>

In article <37E2DB22.1FE2E695@mail.cor.epa.gov>,
David Cassell  <cassell@mail.cor.epa.gov> wrote:
>> I want to do like this :
>> 
>> INPUT :
>> 
>> $line = '<p>You can find at<a href =
>> "http://www.yahoo.com">Yahoo</a>';
>
>I would recommend using HTML::Parser and following
>the guidelines in the docs.  Kragen gave you a nice
>regex answer, but he knows from experience where to use
>that and where *not* to.

You honor me too highly.  I probably *don't* know where not to use it
yet :)

I do know I wouldn't trust it too much.

>  Regexes break in a variety
>of icky ways on real-world HTML.  Read the FAQ for a
>few common examples.

Thanks, I will.  You mean the Perl FAQ?

>P.S.  Abigail will probably tell you that HTML::Parser
>does a less-than-ideal job of parsing HTML.  But nothing's
>perfect.

On HTML, nothing is perfect; everything deals with bad HTML in its own
special way; most of them manage to deal with it OK.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Fri Sep 17 1999
52 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: Fri, 17 Sep 1999 15:41:01 +0000
From: Warren Bell <resource@ERASEjps.net>
Subject: Re: How to test for file Perl
Message-Id: <37E2610D.F6495D3A@ERASEjps.net>

Tom Christiansen wrote:
> 
> In comp.lang.perl.misc,
>     Warren Bell <resource@jps.net> writes:
> :I'm trying to write a script that needs to check a directory for a file
> :as part of an if then statement.  I can't seem to get it, it keeps
> :comming up with errors.  How can I do this?  Somthing like:
> :
> :$file="/home/user/file"
> :
> :if ($file){
> :do this  LOOK IT IS A RACE CONDITION!
> :}else{
> :do this  LOOK IT IS ANOTHER RACE CONDITION!
> :}
> 
> I hope you understand that you've probably just left yourself
> open to a race condition.
> 
> --tom
> --
> /* This bit of chicanery makes a unary function followed by
>    a parenthesis into a function with one argument, highest precedence. */
>         --Larry Wall in toke.c from the perl source code

First, What's a race condition? And second, That wasn't actual code I
was using, just an example of what I need it to do.  I might as well
used:

if (some way to test for file) then
do this
if that doesnt work, then
do this


------------------------------

Date: 17 Sep 1999 21:43:02 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: How to test for file Perl
Message-Id: <x7r9jxgfkp.fsf@home.sysarch.com>

>>>>> "WB" == Warren Bell <resource@ERASEjps.net> writes:

  WB> Tom Christiansen wrote:
  >> I hope you understand that you've probably just left yourself
  >> open to a race condition.

  WB> First, What's a race condition? And second, That wasn't actual code I
  WB> was using, just an example of what I need it to do.  I might as well
  WB> used:

well, i was right. he doesn't know waht a race condition is, so tom's
telling him about it is not useful.

quick question: what is the context of this program? will it be running
more than one copy at a time (like cgi programs can do)? or is it just a
simple file munging program you use by itself?

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


------------------------------

Date: Sat, 18 Sep 1999 00:48:50 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Lambda calculus stuff in Perl
Message-Id: <SjBE3.17516$N77.1287822@typ11.nn.bcandid.com>

In article <Pine.NEB.3.96.990917165735.21888C-100000@www.yawp.com>,
Mike Stone  <mike@yawp.com> wrote:
>[Kragen wrote:]
>> ITYM a DPDA, not a DFA. 
>
>Deterministic Finite-state Automaton.. that's the term they use in the
>Dragon book, and it sorta got burned into my skull on the N+(however
>many)th reading.   i'm not familiar with DPDA off the top of my head, but
>assume they're synonymous.. Deterministic, Probabilistically Directed
>Automaton, p'raps?   

No.  A DFA can recognize regular languages, like those described by
regular expressions (without backreferences -- real regular expressions
with just *, |, grouping, and sequence).  To recognize a context-free
language, which is I assume you meant when you were talking about
shifting and reducing, you need a pushdown automaton, which is a
nondeterministic finite automaton attached to a stack.  In general,
rather than try to simulate PDAs, we simulate deterministic PDAs, which
are deterministic finite automata attached to stacks, and which are
strictly less powerful than vanilla nondeterministic PDAs.  That's what
LR parsers are -- DPDAs, with the state-transition tables encoded
explicitly.

If you want to recognize (or parse) a regular language, you don't need
to shift or reduce.  You can just transition from state to state.

Maybe you should read the Dragon Book N+1 times :)

>uh, no.. that's not something i missed, per se.. more like a fundamental
>consequence of the point i was making.   (hey, what the heck.. at least
>you spotted it, right? ;-)
>
>look at is this way:  there are only two things the routine can possibly
>do:  terminate or not terminate.   by definition, the sum of the
>probabilities for those two outcomes is 1.

Yes, of course.

>the chance of reaching recursion N is a simple conditional probability,
>i.e.: the product of the probabilities of all events in the condition.  
>the probability of getting to recursion N is the probability of getting
>to recursion N-1, times the probability of recurring again.   since the
>probability of recurring again is the same every time, we're just
>multiplying the same number by itself N times, so the probability of
>reaching recursion N is Precur**N.

No, the probability of recurring again is not the same every time.  If
we reach the second level of recursion twice, the probability of
continuing to the third level of recursion is the square of the
probability that one of those second-level productions will continue to
the third level.

Your model implies that the probability of terminating in a finite
amount of time is 1.  This is not the case.

Let's look at a simplified model.

sub deep {
	deep, deep if rand > 0.1;
}

This creates a nice deep tree of recursion, which will usually never stop.

The probability of reaching level 0 is 1.

The probability of terminating on level 0 is 0.1.

The probability of reaching level 1 is therefore 0.9.

So level 1 may have 2 calls (P = 0.9) or 0 calls (P = 0.1).  The mean
number of calls is 1.8.

If level 1 is reached with 2 calls, there are four possibilities:
first call       second call        P
recurses         doesn't recurse    0.9 * 0.1 = 0.09
doesn't recurse  recurses           0.1 * 0.9 = 0.09
recurses         recurses           0.9 * 0.9 = 0.81
doesn't recurse  doesn't recurse    0.1 * 0.1 = 0.01

So if level 1 is reached, the probability that level 2 is reached with
at least one call is 0.99.  This means the probability that level 2 is
reached with at least one call is 0.9 (P(reaching level 1)) * 0.99
(P(reaching level 2 given level 1 is reached). That's 0.891.

Level 2 has three possibilities: no calls (P=0.109), two calls (P =
0.18 * 0.9 = 0.162), or four calls (P = 0.81 * 0.9 = 0.729).  Note that
the mean number of calls on level 2 is 3.24, more than for level 1.

The probability of termination on any level can be calculated by this
method.  The sum of all these probabilities is, I think, not 1.

>and the routine is guaranteed to terminate after (at most) an infinite
>number of recursions.. which isn't exactly a glowing reccommendation if
>you stop and think about it.

Well, it depends.  I'd be perfectly happy with an algorithm that would
sometimes need more memory than I have, and therefore fail, but only
one out of 10^1_000_000_000 runs.  :)

That's why I wanted to calculate the probability.

>so.. flipping the numbers back over again, as long as the probability of
>getting a varref is less than 1.. no matter how close to 1 it gets.. there
>will always be a vanishingly small chance of infinite recursion.   there's
>no set of parameters for the routine which both allow probabilistic
>recursion *and* guarantee termination in at most N recursions, where N is
>less than infinity.. that's just the way the beast works.   if you want
>probabilistic recursion *and* an absolute guarantee of termination after
>at most N(finite) recursions, you need to handle those requirements
>separately.

I can't get an absolute guarantee of termination in this universe.  My
computer might break.  If the probability of the algorithm running
correctly and not terminating is insignificant compared to the
probability my computer might break while running it, I don't care
about the algorithm's uncertainty.

This is also why I trust the factors of PGP keys to be prime.  :)

>to figure the *average* (statistical mean) number of times the routine
>will recur before terminating, you just calculate the number of recursions
>necessary to give a 50% chance of termination.   assuming your random
>number generator produces a uniform distribution, half the runs will
>terminate before that point, and half will terminate after it.   the two
>halves cancel each other out, making N50 the average number of recursions
>per execution.   it's a pretty simple function:

That's the median, not the mean.  They are the same for normal
distributions.  They are very different for distributions like the one
you thought this function had; indeed, if there is indeed a finite
probability of nontermination, the median can be something normal like
3 while the mean is infinite.

Thanks for the insight, and good luck with your parser.

Kragen
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Fri Sep 17 1999
52 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: 17 Sep 1999 20:06:52 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Line chart
Message-Id: <slrn7u5pi7.1j0.abigail@alexandra.delanet.com>

C. Lousberg (clousberg@voslogistics.com) wrote on MMCCVIII September
MCMXCIII in <URL:news:7rsugp$eua$1@rubens.telebyte.nl>:
\\ How do I make a line-chart on our homepage from a  SQL-Database ?

Well, it's this an extremely broad question? 

You could of course use Sybase 11.9.3 and its extended procedures, which
call gnuplot to draw a line chart for you, but what does that have to
do with Perl?

\\ Someone have an example that I can use ?


Well, I have an example that draws charts from a Perl program querying
an SQL database for information. But that doesn't do the work from within
the database.

Anyway, here it goes, though I doubt it will be helpful.


#!/opt/perl/bin/perl -w

use lib qw {/home/abigail/Perl /home/abigail/Sybase};

use strict;

use Getopt::Long;

use Sybase;
use Servers;

$ENV {SYBASE} ||= $SYBASE;

sub adjust_date ($);

my $PLOT   = '/usr/local/bin/gnuplot';
my $BIN    = '/usr/local/bin';

GetOptions ("server=s"       =>  \my $server_name, 
            "date=s"         =>  \my $date,
            "title=s"        =>  \my $title,
            "terminal=s"     =>  \my $terminal,
            "background=s"   =>  \my $col_background,
            "borders=s"      =>  \my $col_borders,
            "axes=s"         =>  \my $col_axes,
            "col_users=s"    =>  \my $col_users,
            "col_cpu=s"      =>  \my $col_cpu,
            "col_busy=s"     =>  \my $col_busy,
            "col_io=s"       =>  \my $col_io,
            "col_down=s"     =>  \my $col_down,
            "col_read=s"     =>  \my $col_read,
            "col_write=s"    =>  \my $col_write,
            "col_errors=s"   =>  \my $col_errors,
            "col_load=s"     =>  \my $col_load,
            "output=s"       =>  \my $output
);

my $alex_server = query_server ("alexandra") or die "Didn't find alexandra!\n";
my $alexandra   = Sybase -> new (server    =>  $alex_server -> {name},
                                 user      =>  $alex_server -> {user},
                                 password  =>  $alex_server -> {password},
                                 database  =>  'logging')
                  or die "Couldn't connect to alexandra!\n";
my $server      = query_server ($server_name)
                        or die "Didn't find $server_name!\n";

unless ($date) {
    $date =  localtime;
    $date =~ s/\w+\s+(\w+)\s+(\d+)\s+[\d:]+\s+(\d+)/$1 $2 $3/;
}
my $DATE      = $date;
my $SERVER    = $server -> {name};
my $MAX_USERS = $server -> {max_user_connections};
my $ENGINES   = $server -> {engines};
my $MAXCPU    = $ENGINES * 100;
my $TITLE     =  defined $title ? $title : "$DATE: $SERVER";
my $MAXERRORS = $server -> {max_errors} || 2;
my $MAXDISKS  = $server -> {max_disk_io};
my $CPUS      = $server -> {cpus};


# Figure out the terminal setting.
my $TERMINAL  = "";
if (defined $terminal) {
    unless (lc $terminal eq 'gif') {
        die "Terminal type $terminal not supported\n";
    }
    $col_background ||= 'xffffff';
    $col_borders    ||= 'x000000';
    $col_axes       ||= 'x404040';
    $col_cpu        ||= 'x0055ff';
    $col_users      ||= 'xff0000';
    $col_down       ||= 'xcdb5cd';
    $col_io         ||= 'x009900';
    $col_busy       ||= 'xffaa44';
    $col_read       ||= 'x00ff00';
    $col_write      ||= 'xffaa00';
    $col_errors     ||= 'xff0000';
    $col_load       ||= 'xffff88';
    $TERMINAL = "set terminal gif size 640, 480 "             .
                "    $col_background $col_borders $col_axes " .
                "    $col_cpu $col_users $col_down";
}
my $OUTPUT    = "";
my $OPTIONS   = "";
if (defined $output) {$OUTPUT  = qq {set output "$output.$$.1"}}
else                 {$OPTIONS = "-persist"}

my @users  = $alexandra -> do_command (command => qq {
                 select   ts, connections, up
                 from     user_connections, server_names
                 where    server_names.server_name   = '$SERVER'         and
                          user_connections.server_id =
                              server_names.server_id                     and 
                          user_connections.ts       >= '$DATE 00:00:00'  and
                          user_connections.ts       <= '$DATE 23:59:59'
                 order by ts
             });


my @cpu    = $alexandra -> do_command (command => qq {
                 select   ts, busy, io, machine_load
                 from     cpu_usage, server_names
                 where    server_names.server_name   = '$SERVER'         and
                          cpu_usage.server_id        =
                              server_names.server_id                     and
                          cpu_usage.ts              >= '$DATE 00:00:00'  and
                          cpu_usage.ts              <= '$DATE 23:59:59'
             });


my @disks  = $alexandra -> do_command (command => qq {
                 select   ts, io_read, io_write, io_errors, up
                 from     disk_usage, server_names
                 where    server_names.server_name   = '$SERVER'         and
                          disk_usage.server_id       =
                              server_names.server_id                     and
                          disk_usage.ts             >= '$DATE 00:00:00'  and
                          disk_usage.ts             <= '$DATE 23:59:59'
             });


foreach my $point (@users) {$point -> [0]   = adjust_date $point -> [0];
                            $point -> [2]   = (1 - $point -> [2]) * $MAX_USERS;}
foreach my $point (@cpu)   {$point -> [0]   = adjust_date $point -> [0];
                            $point -> [3] ||= 0;
                            $point -> [3]  *= $MAXCPU / $CPUS;
                            $point -> [4]   = ($point -> [1] + $point -> [2]) *
                                               $MAX_USERS / $MAXCPU;}
foreach my $point (@disks) {$point -> [0]   = adjust_date $point -> [0]; 
                            $point -> [3]  *= $MAXDISKS / $MAXERRORS;
                            $point -> [4]   = (1 - $point -> [4]) * $MAXDISKS;
                            for my $i (1 .. 4) {
                                $point -> [$i] = 1 if $point -> [$i] < 1;}}

open (PLOT, "| $PLOT $OPTIONS") or die "Failed to open $PLOT: $!\n";
print PLOT <<EOT;
$TERMINAL
$OUTPUT
set title     "$TITLE"
set data style boxes
set xdata      time
set format     x "%R"
set format     y "%5g"
set ylabel    "Users"
set ytics      border nomirror norotate
set y2label   "CPU"
set y2range   [0:$MAXCPU]
set y2tics     border nomirror norotate
set grid       xtics ytics
set timefmt   "%b %d %Y %H:%M:%S"
plot ["$DATE 00:00:00":"$DATE 23:59:59"] [0:$MAX_USERS]    \\
     '-' using 1:8         smooth unique title "cpu",      \\
     '-' using 1:5         smooth unique title "users",    \\
     '-' using 1:6                       title "down" 
@{[map {"@$_\n"} @cpu]}
e
@{[map {"@$_\n"} @users]}
e
@{[map {"@$_\n"} @users]}
e
EOT
close PLOT or die "Failed to close $PLOT: $!";


if ($terminal eq 'gif') {

    my $output2;
    if (defined $output) {
        $output2 =  "$output.$$.2";
        $OUTPUT  =~  s/\.1"/.2"/;
    }

    $TERMINAL = "set terminal gif size 640, 240 "             .
                "    $col_background $col_borders $col_axes " .
                "    $col_load $col_io $col_busy $col_down";

    open (PLOT, "| $PLOT $OPTIONS") or die "Failed to open $PLOT: $!\n";
    print PLOT <<EOT;
$TERMINAL
$OUTPUT
set data style boxes
set xdata      time
set format     x "%R"
set format     y "%5g"
set ylabel    "CPU"
set ytics      border nomirror norotate
set y2label   "Load"
set y2range   [0:$CPUS]
set y2tics     border nomirror norotate
set grid       xtics ytics
set timefmt   "%b %d %Y %H:%M:%S"
plot ["$DATE 00:00:00":"$DATE 23:59:59"] [0:$MAXCPU]        \\
     '-' using 1:7                       title "load",      \\
     '-' using 1:6         smooth unique title "cpu/io",    \\
     '-' using 1:5         smooth unique title "cpu/busy",  \\
     '-' using 1:6                       title "down" 
@{[map {"@$_\n"} @cpu]}
e
@{[map {"@$_\n"} @cpu]}
e
@{[map {"@$_\n"} @cpu]}
e
@{[map {"@$_\n"} @users]}
e
EOT
    close PLOT or die "Failed to close $PLOT: $!";

    my $output3;
    if (defined $output) {
        $output3 =  "$output.$$.2";
        $OUTPUT  =~  s/\.2"/.3"/;
    }

    $TERMINAL = "set terminal gif size 640, 240 "             .
                "    $col_background $col_borders $col_axes " .
                "    $col_read $col_write $col_errors $col_down";

    open (PLOT, "| $PLOT $OPTIONS") or die "Failed to open $PLOT: $!\n";
    print PLOT <<EOT;
$TERMINAL
$OUTPUT
set logscale   y
set data style boxes
set xdata      time
set format     x "%R"
set format     y "%5g"
set ylabel    "Disk usage"
set ytics      border nomirror norotate
set y2label   "Disk Errors"
set y2range   [0:$MAXERRORS]
set y2tics     border nomirror norotate
set grid       xtics ytics
set timefmt   "%b %d %Y %H:%M:%S"
plot ["$DATE 00:00:00":"$DATE 23:59:59"] [1:$MAXDISKS]        \\
     '-' using 1:5         smooth unique title "disk/read",   \\
     '-' using 1:6         smooth unique title "disk/write",  \\
     '-' using 1:7                       title "disk/errors", \\
     '-' using 1:8                       title "down" 
@{[map {"@$_\n"} @disks]}
e
@{[map {"@$_\n"} @disks]}
e
@{[map {"@$_\n"} @disks]}
e
@{[map {"@$_\n"} @disks]}
e
EOT
    close PLOT or die "Failed to close $PLOT: $!";

    if (defined $output) {
        system "$BIN/giftopnm $output.$$.1  > $output.$$.1.pnm";
        system "$BIN/giftopnm $output.$$.2  > $output.$$.2.pnm";
        system "$BIN/giftopnm $output.$$.3  > $output.$$.3.pnm";
        system "$BIN/pnmcat -topbottom $output.$$.1.pnm $output.$$.2.pnm " .
               "$output.$$.3.pnm | $BIN/ppmtogif > $output.$$.1 2> /dev/null";
        unlink ("$output.$$.1.pnm", "$output.$$.2.pnm", "$output.$$.3.pnm") == 3
                  or die "Failed to delete pnm files: $!\n";
        unlink "$output.$$.2" or die "Failed to delete $output.$$.2: $!\n";
        unlink "$output.$$.3" or die "Failed to delete $output.$$.3: $!\n";
    }
}


if (defined $output) {
    rename "$output.$$.1", $output or die "Failed to rename $output.$$: $!\n";
    chmod 0644, $output            or die "Failed to chmod  $output: $!\n";
}


sub adjust_date ($) {
    local $_ = shift;
    s/  ?(\d+):(\d+):(\d+):\d+([AP]M)/
           sprintf " %02d:%02d:%02d", ($4 eq 'PM' && $1 != 12 ? $1 + 12 :
                                       $4 eq 'AM' && $1 == 12 ? $1 - 12 : $1),
                                       $2, $3/e;
    $_
}


__END__


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";`$@`'


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 836
*************************************


home help back first fref pref prev next nref lref last post