[13420] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 830 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 17 11:19:56 1999

Date: Fri, 17 Sep 1999 08:05:12 -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: <937580712-v9-i830@ruby.oce.orst.edu>
Content-Type: text

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

Today's topics:
    Re: Are threads the way to go?  Design Advice <dan@tuatha.sidhe.org>
    Re: cgi help (Kragen Sitaker)
    Re: cgi not working (Kragen Sitaker)
    Re: CONTEST: Range Searching (Benjamin Franz)
    Re: Diff of string arrays. <aqumsieh@matrox.com>
    Re: Encrypting (and decrypting) password (Kragen Sitaker)
    Re: help! (Kragen Sitaker)
    Re: Help: No pipe output. (Kragen Sitaker)
    Re: How can I know if string have points? (Kragen Sitaker)
    Re: How to assign filehandle to scalar? <aqumsieh@matrox.com>
    Re: how to create (and ref) anonymous objects <aqumsieh@matrox.com>
        How to split HTML text ? <choijinh@hitel.net>
    Re: How to split HTML text ? (Kragen Sitaker)
    Re: How to test for file Perl (Kragen Sitaker)
    Re: How to test for file Perl <tchrist@mox.perl.com>
    Re: Lambda calculus stuff in Perl (Kragen Sitaker)
    Re: Making and using a DB. (Help!!!) <mattking@techie.com>
    Re: optimizing execution speed (Kragen Sitaker)
    Re: Parsing Tab Delimited File (Kragen Sitaker)
    Re: Perl + ICQ cw@dwc.ch
        perl programmer needed <007@blowpop.co.uk>
    Re: Problem with open() and probably something else (David Wall)
    Re: Question on Hash of Hash <aqumsieh@matrox.com>
    Re: Redirection of POST CGI in Perl <flavell@mail.cern.ch>
    Re: Return values of stat( file ) <jonathan.stowe@dircon.net>
    Re: trimming spaces from a string (Greg Bacon)
    Re: What happens with this slice? <aqumsieh@matrox.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 17 Sep 1999 13:23:22 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Are threads the way to go?  Design Advice
Message-Id: <ehrE3.14093$wW2.23326@news.rdc1.ct.home.com>

Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> Ilya Zakharevich <ilya@math.ohio-state.edu> wrote in comp.lang.perl.misc:
>>[A complimentary Cc of this posting was sent to Dan Sugalski 
>><dan@tuatha.sidhe.org>],
>>who wrote in article <D9OD3.13641$wW2.13459@news.rdc1.ct.home.com>:
>>> > Is there another way to do this without threads? (Since I have no 
>>> > experience in perl threads).
>>> 
>>> Fork is probably the better way to do this.
>>
>>Keep in mind memory considerations as well.  As experiments show,
>>memorywise fork() gives almost no advantage over running separate Perl
>>processes (14% difference reported on Solaris - with total footprint
>>circa 9G).

> Why *should* fork give a memory advantage?  Where does the 14% savings
> come from anyway?

Any memory page left untouched after the fork should stay shared between
the parent and child processes, so, for example, the pages that hold the
compiled perl program should share. Perl, unfortunately, tends to touch
lots of memory so most of the memory your program uses ends up changing
after the fork (either by the child or parent) so not much stays shared.

				Dan


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

Date: Fri, 17 Sep 1999 13:42:05 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: cgi help
Message-Id: <NyrE3.16399$N77.1213767@typ11.nn.bcandid.com>

In article <37E1F6EF.8F8D1113@fidata.fi>, Olli Aalto  <olli@fidata.fi> wrote:
>How do I make my script update the client browser
>every second?

That's not a Perl question.  The answer would be the same in any
language:  Refresh: headers, META HTTP-EQUIV pseudo-refresh headers,
server push, Java, or JavaScript.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Thu Sep 16 1999
53 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 13:43:54 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: cgi not working
Message-Id: <uArE3.16402$N77.1214537@typ11.nn.bcandid.com>

In article <7rsu94$rn6$1@nnrp1.deja.com>,  <soulierb@my-deja.com> wrote:
>perl - card.cgi => syntax is ok
>but
>./card.cgi to execute it, i get the message, that there is no such  file
>in my folder
>but if i make a ls in this folder, the card.cgi is in the list.
>
>if i do the same thing with my program.cgi, syntax is ok, and no problem
>to execute it.

Your #! line is wrong.

>Is this a problem with my .cgi extension ?

No.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Thu Sep 16 1999
53 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 14:06:23 GMT
From: snowhare@long-lake.nihongo.org (Benjamin Franz)
Subject: Re: CONTEST: Range Searching
Message-Id: <zVrE3.1091$Qx1.67939@typhoon01.swbell.net>

In article <37e1c82d@cs.colorado.edu>,
Tom Christiansen  <tchrist@mox.perl.com> wrote:
>
>In comp.lang.perl.misc,  snowhare@long-lake.nihongo.org (Benjamin Franz) writes:
>:if (0 == @file_list) {
>:	push (@file_list,'-')
>:}	
>:$last_n++;
>:while (my $file_name = shift @file_list) {
>:	my $open_name = $file_name;
>:	if ($file_name eq '-') {
>:		$open_name = "<&STDIN";
>:		$file_name = '';
>
>Is there some reason why normal <ARGV> isn't what you want?
>You seem to be emulating what it already does.

No particular reason. Old habits from the fact that I don't
write a lot of command line option programs currently.

-- 
Benjamin Franz



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

Date: Fri, 17 Sep 1999 08:16:47 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Diff of string arrays.
Message-Id: <x3y6719hgwh.fsf@tigre.matrox.com>


"Andy Cragg" <andrew_cragg@csi.com> writes:

> Anyone know how to do a quick comparison between two arrays (of strings) and
> return the differences in another array?  Perhaps using cmp?

It depends on what your definition of "difference" is. Your question
is so vaguely posed that I can't decide for sure. But, perhaps you
would be interested in what the FAQs say about this. In perlfaq4:

	How do I compute the difference of two arrays?
	How do I compute the intersection of two arrays?

HTH,
--Ala



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

Date: Fri, 17 Sep 1999 13:39:56 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Encrypting (and decrypting) password
Message-Id: <MwrE3.16389$N77.1213767@typ11.nn.bcandid.com>

In article <0E16861EE7BCD111BE9400805FE6841F0B726A95@c1s5x001.cor.srvfarm.origin-it.com>,
Steve Button <steve.button@nl.origin-it.com> wrote:
>Ethan H. Poole wrote in message <37E14923.DE1C6921@ingress.com>...
>>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.

You could do that.  Or you could XOR it with a known string, repeated n times.

e.g.

#!/usr/bin/perl -w
use POSIX 'ceil';
my $origstring = "Frightening witches";
my @keys = qw(7 71337);
for (@keys) { 
	my $key = ($_ x (ceil(length($origstring)/length)));
	my $ciphertext = 
		$origstring ^ $key;
	print $ciphertext, "\n";
	print $ciphertext ^ $key, "\n";
}

Output:

qE^P_CRY^YP@^CT_RD
Frightening witches
qCZT_CT]ZYPDZCTYV@7
Frightening witches

Obviously you may have to URL-encode strings like these.

Don't worry about people finding out how you're making up your keys --
as you pointed out, the single-character key could be found by
exhaustive keysearch.  The multi-character key could easily be found by
a known-plaintext attack, which sounds feasible in this case, but could
probably also be easily guessed by XORing bits of the ciphertext
together.

Kragen
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Thu Sep 16 1999
53 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 14:10:35 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: help!
Message-Id: <vZrE3.16427$N77.1217161@typ11.nn.bcandid.com>

In article <DhkE3.1427$z5.44488@ndnws01.ne.mediaone.net>,
bob <zorgok@flashmail.com> wrote:
>can someone email/IM me a description of what's on channel 80?
>i then need to make a change and ask them to tell me what changed.
>
>anyone please!

Can anyone see if it's raining outside?  And what time is it?
-- 
<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 13:49:49 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Help: No pipe output.
Message-Id: <1GrE3.16409$N77.1214998@typ11.nn.bcandid.com>

In article <7rse4p$emr$1@news.ntu.edu.sg>,
Daniel Y.L. <linyong2000@990.net> wrote:
>Kragen Sitaker <kragen@dnaco.net> wrote in message
>news:rv6E3.14433$N77.1067283@typ11.nn.bcandid.com...
>> My guess: glim isn't in your path when running as a CGI script.  Why
>> don't you close (PIPEGLIM) or die "problem with glim: $!" instead of
>> just close(PIPEGLIM)ing, and why don't you also check your server error
>> logs.
>
>The C program is in the same directory as my CGI program.  And I found, I
>can run the CGI correctly from UNIX shell.  Only failed when from browser.

Did you check my guess to see whether it was correct?  Did you try my
suggestion?  Everything you say is still consistent with my guess.  .
isn't implicitly in your PATH on Unix, for excellent reasons, but your
ISP may have stuck . explicitly in your PATH when you log in for
convenience, ignoring the security risk.
-- 
<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 14:09:18 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: How can I know if string have points?
Message-Id: <iYrE3.16425$N77.1216981@typ11.nn.bcandid.com>

In article <x7ogf2i0jr.fsf@home.sysarch.com>,
Uri Guttman  <uri@sysarch.com> wrote:
>>>>>> "KS" == Kragen Sitaker <kragen@dnaco.net> writes:
><quote>
>String literals can be represented in three ways in Perl. The first is
>in single quotes.
></quote>
>
>this is interesting. i never found out the other 2 ways! i think he
>means double quoted is the second. and maybe here docs are the third?
>but he never mentions second or third in this context. and what about q
>and qq? qq is not found in the document at all. they may be semantically
>equivilent to '' and "" but they are important sugar even for beginners.
>here docs don't seem to be mentioned either. so the whole section on
>strings only covers single and double quoted strings.

I think part of this is just that it is unfinished.

Barewords would be the sixth or so way; this is probably worth
mentioning for the unfortunate Perl programmer who has to maintain
somebody else's Perl4.

>so this is a worthy but failed attempt to create an in depth tutorial.
>it needs an extensive editing job to clear up the broken logic and
>overly verbose text.

I don't know that the author is interested in reducing the verbosity of
the text.

I'll do my best to help with the other stuff.
-- 
<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 08:26:27 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: How to assign filehandle to scalar?
Message-Id: <x3y3dwdhggc.fsf@tigre.matrox.com>


"Rod B. Nussbaumer" <bomr@lin01.triumf.ca> writes:

> I have a need to read data from a file, and according to
> flags embedded within the file, copy said data to any of
> an arbitrary number of files.  The data stream should be
> directed to a 'current' output file, until a flag is
> detected to re-route to a different (open) file.  

Then you need to be using the IO::File or the FileHandle
modules. These modules are part of the standard Perl distribution and
allow you to store filehandles inside regular scalars.

> My test code won't compile, and I guess I don't grasp
> some fundamental concept here, despite considerable research
> in the Camel book, and past postings here.  Enclosed is
> the sample code, annotated with the compiler error meessages.
> 
> Enlighten me, please.

As much as I like and respect the Camel, my first and last resort will
always be the perldocs and perlfaqs that are installed on your
system. They are more complete. A relevant faq appears in perlfaq5:

	How can I make a filehandle local to a subroutine?  
	How do I pass filehandles between subroutines?  
	How do I make an array of filehandles?
HTH,
--Ala



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

Date: Fri, 17 Sep 1999 08:42:18 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: how to create (and ref) anonymous objects
Message-Id: <x3y1zbxhfpx.fsf@tigre.matrox.com>

Pat Trainor <ptrainor@bettyjo.downcity.net> writes:

[snip a lot of unnecessary (accidental?) irrelevant stuff]

> Greets
> 
>         I need to create objects anonymously, and have been frustratingly
> unsuccessful. Given: 

What do you mean by anonymously??

> #!/usr/bin/perl

You should stick a '-w' up there. It enables warnings. Also, 'use
strict;' would be a very good idea.

> #
> # file: testfred
> #
> use Module; 
> for ($fred=1;$fred<10;$fred++) {

a more Perlish way of doing the above would be:

	for my $fred (1 .. 9) {

>         ${$fred} = Pluckit->new;

This is a symbolic reference to a variable called $1, $2, etc ..
Those variables are special in Perl, and are readonly. So you can't
modify them, hence your error.

Perhaps all you need is an array:

	$ary[$fred] = Pluckit->new;

>         ${$fred}->obj_id("$fred");

	$ary[$fred]->obj_id($fred);

The quotes around $fred are unnecessary.

> }
> print "id is: ", ${5}->obj_id, "\n";

	print "id is: ", $ary[5]->obj_id, "\n";

> failure on compile is:
> Modification of a read-only value attempted at ./testfred line 6.
> 
> Module.pm is a stock store and retrive module, excerpt:
> 
> package Module;

[snip body of module]

Where is Pluckit defined??

> 	I'm using numbers here, but it doesn't matter what is used for
> $fred. It seems that the literal '$fred' is being used to make the objects
> and not what $fred is carrying at the time.

No. That only happens if you stick $fred between single quotes or q//

	'$fred'
	q/$fred/

If $fred was not a small number, then you'd better use a hash:

	my %hash;
	for my $fred (qw/Fred Wilma Barney Betty/) {
		$hash{$fred} = Pluckit->new;
		$hash{$fred}->obj_id($fred);
	}

HTH,
--Ala



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

Date: Fri, 17 Sep 1999 22:31:39 +0900
From: Choi Jin-Ho <choijinh@hitel.net>
Subject: How to split HTML text ?
Message-Id: <37E242BB.B3894EF0@hitel.net>

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 ...).

I want to do like this :

INPUT :

$line = '<p>You can find at<a href =
"http://www.yahoo.com">Yahoo</a>';

OUTPUT :

@line = ('<p>', 'You', 'can', 'find', 'at',
         '<a href = "http://www.yahoo.com">', 'Yahoo', '</a>');


I could not just split with space because HTML tags can
contain spaces.

Anyone can help me ? I tried some pattern-matching code,
but as I'm novice, I could not get correct result.

Thanks in advance.


Choi Jin-Ho
webmaster of http://heartkorea.com


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

Date: Fri, 17 Sep 1999 14:32:09 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: How to split HTML text ?
Message-Id: <JhsE3.16439$N77.1218986@typ11.nn.bcandid.com>

In article <37E242BB.B3894EF0@hitel.net>,
Choi Jin-Ho  <choijinh@hitel.net> wrote:
>INPUT :
>
>$line = '<p>You can find at<a href =
>"http://www.yahoo.com">Yahoo</a>';
>
>OUTPUT :
>
>@line = ('<p>', 'You', 'can', 'find', 'at',
>         '<a href = "http://www.yahoo.com">', 'Yahoo', '</a>');
>
>
>I could not just split with space because HTML tags can
>contain spaces.

Hmm.  You should probably use one of the HTML:: modules.

Here's a program that works for your simple example.

#!/usr/bin/perl -w
use strict;
my $line = '<p>You can find something at <a href = 
		"http://www.yahoo.com">Yahoo</a>';
my @line;
push @line, $1 while $line =~ /([^\t <>]+|<(?:[^">]+|"[^"]+")*>)/g;
print join (', ', map { "'$_'" } @line), "\n";

Outputs:

'<p>', 'You', 'can', 'find', 'something', 'at', '<a href = 
		"http://www.yahoo.com">', 'Yahoo', '</a>'

-- 
<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 14:34:08 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: How to test for file Perl
Message-Id: <AjsE3.16441$N77.1219269@typ11.nn.bcandid.com>

In article <37e1fefc.939192767@frettir.simnet.is>,
Helgi Briem <helgi@NOSPAMdecode.is> wrote:
>if (-e $file ) {dostuff};
>
>-e is the "exists" file checking switch.
>There are other useful ones such as 
>-d (checks for a directory)  
>-s (checksfor size)
>-w (checks if writeable)

Yes.  perldoc perlfunc or perldoc -f -e.
-- 
<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 08:53:24 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How to test for file Perl
Message-Id: <37e255e4@cs.colorado.edu>


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


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

Date: Fri, 17 Sep 1999 13:58:20 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Lambda calculus stuff in Perl
Message-Id: <0OrE3.16417$N77.1214882@typ11.nn.bcandid.com>

[First I got this in email, and replied in email.  Then I saw Mike had
sounded his barbaric yawp over the rooftops of Usenet too, not just
email, so I'm posting my email reply here too :)]

Thanks for all the comments!

You write:
> i've only given it a quick skim so far.. top-down parser, yes?   it's
> easy to be wrong, but i didn't see anything on the fly that looked like
> shift-reduce code.

Yep.

> hmm.. well, to give one of your questions a rough answer, tokenization in
> both top-down and bottom-up parsers usually happens in O(n) time.

What I'm worried about is that the process of extracting a token from
the string (with s///) might be O(N) in the length of the remaining
string, instead of O(1), (or O(strlen(token))), which would make it
O(N^2).

> and lessee some more.. "prints out the evaluation sequence".. either that
> means it's (roughly speaking) a macro expander, or that it prints out
> something on the order of a parse tree.

It prints out the original expression, and then tries to beta-reduce it
up to ten times, each time printing out the resulting expression.

You could think of it as a macro expander; perhaps we should call the
lambda-calculus the macro calculus instead :)

> it also has a tendency to pummel your frontal
> lobes into jelly, because you're splitting the work of token
> identification across the boundary of a function-call.

Heh :)

>   life is a lot
> easier if you put the entire token-identification process into the
> lower-level routines, and just iterate over them in the top-level routine:

Makes sense.  parse_lambda || parse_token || parse_app.

> oh, ick.. i'm afraid i don't think much of this, though:
> 
> (new lambda($newvar,$self->[1]->substitute(new varref($newvar),$self->[0]
> )->substitute($replacement, $var)))
> 
> give us a coupla temp variables there, wouldja luv?

Sorry!  :)  I was thinking in Scheme, where this is a little bit more
natural.

If you read the comments above, they say something to the effect of
,\c.b[c/a][x/y], which is what the above says.

Temp variables *would* make it more readable.  my $alpha_renamed_body.

> half a mo.. am i right in thinking that you're building the parse tree
> in-situ?   an object starts as a string, and transforms itself into a node
> of the parse tree in its substitute() routine?

No -- parse_* builds the parse tree from strings.  substitute() just
evaluates the resulting expressions by beta-reduction.

> your potentially infinite recursion in random_expr() can be solved fairly
> easily.. keep a global variable named $DEPTH which is incremented upon
> entry to the routine, and decremented upon exit:

Yes, I could certainly do that.  In reality, though, random_expr()
apparently always terminates for these values of the probability
parameters.  What I'd like is a way of understanding why :)

If this were a program I was using for something important, I'd make
sure that it worked.  But it's a hack, and $DEPTH would detract from
its already-questionable elegance :)

> each term in the sum will be .468 * (.532)**N, i.e.: the probability of
> terminating on pass N times the chance of *getting* to pass N.  that's a
> simple geometric progression, so we're looking for the limit as N goes to
> infinity of:
> 
> .468 * ((1 -.532**N) / (1 - .532))  ==  .468 * (1/.468)  ==  1.
> 
> and that's pretty much what intution would suggest:  the function is only
> guaranteed to terminate after infinite recursions, but at least now you
> can calculate the probability of termination on or before recursion N:

You're missing something.  With this calculation, you have demonstrated
that it will always probabilistically terminate, regardless of the
actual probability parameters, as long as the probability of varref is
nonzero.

If the first two levels of recursion (what you're calling a "pass")
produces an application whose operator and operand are both
applications, the probability of terminating at the next level (with
something like ((a)b)(c)d, or something where some of those variables
are replaced by ,\x.y for x and y being variables) is not .468 * .532,
but rather .468**4 * .532, because there are four independent events
we're considering here: does a expand to something that terminates
immediately?  does b? does c? does d?

That's what tripped me up.

> offhand, do you have a copy of the "Gang of Four" book[1]?

Nope -- sorry!

>   the
> Interpreter pattern gives you a simple framework for building well behaved
> top-down parsers with objects.   worth a read, if you haven't seen it yet.

I'll check it out.

I'm pretty sure the *parser* part of the program works perfectly,
except for the bugs I mentioned :)

> personally, i'm still trying to get my head around OO shift-reduce
> parsers.   the shifting and reducing parts are easy.. it's creating a set
> of objects that read the language spec and assemble themselves into an
> efficient DFA that's a pain.

ITYM a DPDA, not a DFA.  So you're generating tables at runtime using
something like LALR(1)?  Youch.

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


-- 
<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:56:29 +0200
From: "Matt King" <mattking@techie.com>
Subject: Re: Making and using a DB. (Help!!!)
Message-Id: <7rtfb2$cf0$1@news.uk.ibm.com>

Followup question: What about Oracle DB? Is there a package for this
somewhere? I'm looking at there web site now, and it apears that it is
possible....... Does Perl already have a DB package for it, or do I have to
find, register, and download there software?

Matt
Eric Bohlman <ebohlman@netcom.com> wrote in message
news:7rs94i$b24@dfw-ixnews6.ix.netcom.com...
> DB_File is available for ActivePerl and can be installed with PPM.





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

Date: Fri, 17 Sep 1999 14:25:24 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: optimizing execution speed
Message-Id: <obsE3.16435$N77.1218474@typ11.nn.bcandid.com>

In article <19990917025949.01880.00001118@ng-ci1.aol.com>,
BLUESRIFT <bluesrift@aol.com> wrote:
>The following questions are asked in the context of Perl scripts running on an
>Apache Unix server written for web browsers. I want to learn techniques that
>will not necessarily lead to faster written code, but faster execution of
>scripts that I write for others to use.  I am assuming that it is indeed
>possible to create code that appears elegant but may actually execute more
>slowly. For example, as a beginner I may be tempted to make my life easier by
>relying on CGI.pm but intiutively I believe there must be a performance cost
>with use of such modules.

There is a significant performance cost to loading CGI.pm.  I think the
performance cost of using routines from CGI.pm is quite small -- I
don't know if it exists at all.

If you want your CGI scripts to run fast, don't try to optimize them.
Instead, switch from CGI to FastCGI or mod_perl.

>What I am looking for is general advice on optimizing the execution speed of
>Perl scripts.  This newsgroup may not be forum for such questions as:
>
>"At what point is it better to modularize an application into separately called
>script files as opposed to calling subroutines within the same file?"

The only difference is an open() and a close() call, and possibly an
extra read().  We're talking microseconds here.

#!/usr/bin/perl -w
use strict;
use Benchmark;
timethese (1000000, 
	{'null' => sub { },
	'openclose' => sub { open FOO, "<$0" or die "damn $!"; close FOO }
	}
);

Benchmark: timing 1000000 iterations of null, openclose...
      null: 12 wallclock secs ( 8.19 usr +  0.01 sys =  8.20 CPU)
 openclose: 59 wallclock secs (39.27 usr +  4.40 sys = 43.67 CPU)

 . . . so doing a million open/close system calls took 4.4 seconds.  So 
on this machine (an ancient Sparc 20 running Solaris 2.6) an open/close
takes 4.4 microseconds.

Executing two typical Perl statements, on the other hand, took 39.27
seconds, minus 8.19 seconds of simple overhead, for 31.08 seconds.
About 15 microseconds per statement.

My machine is
SunOS kirk 5.6 Generic_105181-13 sun4m sparc SUNW,SPARCstation-20

>"At what point is it better to use subroutines at all instead of simply
>repeating redundant code?"

When the redundant code is longer than five or ten characters.  The
real cost of redundant code is not that it makes your program slower to
parse, although it does, but that it makes your program very difficult
to test or maintain.
-- 
<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 14:52:42 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Parsing Tab Delimited File
Message-Id: <_AsE3.16454$N77.1220683@typ11.nn.bcandid.com>

In article <slrn7u3cvu.vd4.abigail@alexandra.delanet.com>,
Abigail <abigail@delanet.com> wrote:
>[] Perhaps you have a simpler method of parsing Tom's "evil" format than
>[] the long regex I posted on this thread?  IMHO, Tom's for/split is
>[] *much* simpler, and likely more robust.
>
>Would it also be much simpler in a language more likely to be used than
>Perl by CSV reading/writing applications, like C?

Well, Kernighan & Pike's latest (TPOP) has a sample CSV library in C.
A straightforward quick-and-dirty CSV implementation -- which strips
quotes around fields, but doesn't allow quoted commas, and has a truly
awful interface largely due to being written in C -- is 13 lines of
code plus 9 lines to deal with the quotes.  It uses a simple strtok()
loop to find the commas: two lines.

The second version, which deals with doubled doublequotes and commas in
fields, spends 29 lines on figuring out where fields begin and end and
16 lines on removing quotes.  (The whole thing, mostly dealing with
memory allocation, deallocation, and out-of-memory errors, is 3 + 3 + 8
+ 35 + 10 + 11 + 29 + 16 + 10 lines, for a total of 125 lines.)

So yeah.

-- 
<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:52:36 +0200
From: cw@dwc.ch
Subject: Re: Perl + ICQ
Message-Id: <37E247A4.AB7507B@dwc.ch>

Jordan Hiller wrote:
> 
> Is there any sort of script or module to send ICQ messages and check ICQ
> online status' from Perl?

Check out http://netizen.com.au/~bekj/code/Net-ICQ/ (it should be available on CPAN too).
AFAIK it's incomplete, not all functions have been implemented properly.

-w


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

Date: Fri, 17 Sep 1999 14:22:57 +0100
From: "James Bond" <007@blowpop.co.uk>
Subject: perl programmer needed
Message-Id: <937574863.14661.0.nnrp-02.d4e4a5b1@news.demon.co.uk>

Perl programmer needed for small project.
Please mail if interested.

Thankyou.

James B




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

Date: Fri, 17 Sep 1999 13:36:47 GMT
From: darkon@one.net (David Wall)
Subject: Re: Problem with open() and probably something else
Message-Id: <37e243fc_1@news2.one.net>

In article <7rsdmv$b24@dfw-ixnews6.ix.netcom.com>, ebohlman@netcom.com (Eric Bohlman) wrote:
>You need to seek() to the beginning of the file here because the OS's file
>pointer is now pointing past the end of the file.  This will lead to 
>various results on different OSs, none of which are likely to be what you 
>want (on FreeBSD, for example, you'll get a block of null bytes the size 
>of the original file before what you write).

Ah...  a light dawns.  I said I'd probably feel stupid.  Unfortunately, I was 
right. Thanks for the help!

David Wall
darkon@one.net


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

Date: Fri, 17 Sep 1999 08:20:04 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Question on Hash of Hash
Message-Id: <x3y4sgthgqz.fsf@tigre.matrox.com>


"Chao Fang" <cfang@nwu.edu> writes:

> > foreach $cookie (keys (%hash))
> > {
> > print "$cookie, $hash->{$cookie}";
> > }
> Try to use print "$cookie, $$hash{$cookie}";
> I am not sure it works, but I think it is how it will be solved. when
> playing with hash of hash, you need more layers of $, @, % also.

This is a pretty useless advice since $hash->{$cookie} is exactly
equivalent to $$hash{$cookie}.

The problem is with his foreach() line. %hash is a separate variable
from $hash, and has not been defined. So no keys exist for it. It
should be changed to %$hash and all will be fine.

--Ala



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

Date: Fri, 17 Sep 1999 14:55:19 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Redirection of POST CGI in Perl
Message-Id: <Pine.HPP.3.95a.990917144822.2616G-100000@hpplus03.cern.ch>

On Fri, 17 Sep 1999, Thomas Worthington wrote:

> I need to be able to redirect POSTed queries from forms 

Then get ready for a hard time, battling with incompatible
specifications (HTTP/1.0 versus HTTP/1.1) and client implementations
that behave quite differently from what the specifications require.

You'll first need to find the right group to ask[1], which this one is
not (no disrespect meant to the many Perl mongers here who do in fact
know the answer).  This is not a Perl language question, regardless. 

> My question is: how do I handle the same thing for POSTed forms?

With considerable difficulty, I'd say.  And all kinds of browser alerts
to your users about re-POSTing submissions.

What you really want is to proxy the request, not to redirect it. IMO.

[1]To which there isn't a unique answer.  Depends on the slant of the
question, might be c.i.w.authoring.cgi, c.i.w.servers.[OS] for
suitable value of [OS], etc.




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

Date: Fri, 17 Sep 1999 14:33:30 +0100
From: Jonathan Stowe <jonathan.stowe@dircon.net>
To: japhy@pobox.com
Subject: Re: Return values of stat( file )
Message-Id: <Pine.WNT.4.10.9909171430400.-648485@desktop83.dircon.net>


[Posted and CC'd]

On Fri, 17 Sep 1999, Jeff Pinyan wrote:

> On Sep 17, Jonathan Stowe blah blah blah:
> 
> > pincky@my-deja.com wrote:
> > >   my $mode = (stat($filename))[2]
> > > 
> > > I can't see any connection between the value of
> > > $mode and the file permissions...
> > > 
> > > From the description of stat
> > > 2 - File mode (file type and permissions)
> > > 
> > > Has anybody any idea of how to change from
> > > stats return value to unix file perms ?
> > > 
> > 
> > Well that value *is* the permissions in octal - if you want to see the
> > permissions in the same way that ls -l presents them you can use the
> > module Stat::lsMode from CPAN.
> 
> That's not really what he asked for at all.
> 
> The value returned by (stat $file)[2] is a number representing NOT ONLY
> the permissions of the file, but also what TYPE of file it is.  If you
> merely want a three-digit permission, you need to bitwise AND this with
> 0777.
> 

Ah I didnt realise that the original poster *hadnt read the documentation*
If that is the  case then surely the appropriate response is 

man perlfunc

Wherein all of this is described.

/J\
-- 
Jonathan Stowe <mailto:Jonathan.Stowe@dircon.net>
Analyst/Programmer, Direct Connection
Martin House, 1 Tranquil Vale, Blackheath, London SE3
<http://www.dircon.net> 



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

Date: 17 Sep 1999 14:11:27 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: trimming spaces from a string
Message-Id: <7rti6f$ia7$2@info2.uah.edu>

In article <gaiE3.15578$N77.1165604@typ11.nn.bcandid.com>,
	kragen@dnaco.net (Kragen Sitaker) writes:

: In article <7rrhb2$5g8$1@info2.uah.edu>, Greg Bacon <gbacon@cs.uah.edu> wrote:
:
: >Such as?
: 
: [...]
:
: Hope this is interesting :)

Sheesh, sorry I asked. :-)  I'd be interested in hearing Mr. Rosler's
comments on the "inferiority" of C<s/\s+//g> in light of this evidence.

Greg
-- 
If you lie to the compiler, it will get its revenge.
    -- Henry Spencer 


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

Date: Fri, 17 Sep 1999 08:58:27 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: What happens with this slice?
Message-Id: <x3yzoylg0eo.fsf@tigre.matrox.com>


Alex Farber <alex@kawo2.rwth-aachen.de> writes:

> for $href ((sort {$a -> {day} <=> $b -> {day}} @loh)[0..9]) # take top 10
> {
>     $href -> {rank} = ++$rank;
> }
> 
> However I get the following error: 
> Modification of a read-only value attempted at ./print-gazeti.pl line 97.
> 
> When I change the code to:
> 
> for $href (sort {$a -> {day} <=> $b -> {day}} @loh)
> {
>     $href -> {rank} = ++$rank;
>     last if $rank == 10;
> }
> 
> everything seems to work fine. But I wonder, why doesn't the first approach
> work? Don't I get a list of 10 hash references inside of  for $href (...) ?
> They point then to the hashes somewhere in mem, why can't I modify the hashes?

It should work.

% perl -wl
my $rank = 0;
my @l;
srand;             
for my $i (0..15) {
        $l[$i] = { day => rand 100 };
}
 
for my $href ((sort { $a->{day} <=> $b->{day} } @l)[0..9]) {
	$href->{rank} = ++$rank;
	print "$href->{rank} $href->{day}";
}
__END__
1 1.043701171875
2 10.77880859375
3 12.48779296875
4 12.738037109375
5 13.5223388671875
6 23.08349609375
7 24.395751953125
8 29.4952392578125
9 31.524658203125
10 32.9345703125

% perl -v
This is perl, version 5.004_04 built for sun4-solaris

What is your version of Perl?

--Ala



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

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 you aren'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 830
*************************************


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