[13416] in Perl-Users-Digest
Perl-Users Digest, Issue: 826 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 17 02:07:30 1999
Date: Thu, 16 Sep 1999 23: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: <937548309-v9-i826@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 16 Sep 1999 Volume: 9 Number: 826
Today's topics:
-d doesn't work with File::Find (Peter Bismuti)
Re: -d doesn't work with File::Find <tchrist@mox.perl.com>
Re: Can Perl talk to Javascript?? <mbrader@aurema.com>
Re: challenge results (Jack Applin)
Re: CONTEST: Range Searching (Don Blaheta)
Re: CONTEST: Range Searching <tchrist@mox.perl.com>
Re: CONTEST: Range Searching <tchrist@mox.perl.com>
Re: CONTEST: Range Searching <tchrist@mox.perl.com>
Re: CONTEST: Range Searching <tchrist@mox.perl.com>
Re: CONTEST: Range Searching <uri@sysarch.com>
help! <zorgok@flashmail.com>
Re: Help: No pipe output. <linyong2000@990.net>
Re: How can I know if string have points? <uri@sysarch.com>
Re: Lambda calculus stuff in Perl <mike@yawp.com>
Re: Parsing Tab Delimited File (Abigail)
Re: perl equivalent of a Unix command line sort? (Eric Bohlman)
Re: Problem with open() and probably something else (Eric Bohlman)
Re: Reading symbolic links (Ron Grunwald-Computer Programmer PGS Tensor Perth)
Re: references in dbms (Eric Bohlman)
Re: Two dimensional array (Abigail)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 17 Sep 1999 04:55:10 GMT
From: bismuti@cs.fsu.edu (Peter Bismuti)
Subject: -d doesn't work with File::Find
Message-Id: <7rshje$qcl$1@news.fsu.edu>
Inside of the 'wanted' subroutine the -d flag doesn't work *unless*
the file is a soft link to a directory. How to fix?!
Consider the following code:
.
.
*name = *File::Find::name; # forcibly import variable name
find(\&wanted,$dir)
.
.
sub wanted(){
print "file = $name ";
if ($name =~ /.*\.html$/){
print ': html';
}elsif (-d $name){ # is file a directory?
print ': directory';
}
print "\n";
}
this code yields:
.
.
file = academics/sysadm #<------ directory
file = academics/tmp.html : html
file = academics/application.html : html
file = academics/ugrad #<------ directory
file = academics/ugrad/ugtree.ps
file = academics/ugrad/index.html : html
.
.
file = jobs : directory #<------ soft link to a directory
.
.
Thanks in advance.
------------------------------
Date: 16 Sep 1999 23:14:53 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: -d doesn't work with File::Find
Message-Id: <37e1ce4d@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
bismuti@cs.fsu.edu (Peter Bismuti) writes:
:Inside of the 'wanted' subroutine the -d flag doesn't work
The problem may be that you are using a file test on a *RELATIVE
PATHNAME*. This, for example, will likely find nothing:
% cd /
% perl -MFile::Find -le 'find sub { -d $File::Find::name && print },@ARGV' tmp
Because find cd's into each directory first!! That's why you need $_
not $name there.
--tom
--
Basically, avoid comments. If your code needs a comment to be understood,
it would be better to rewrite it so it's easier to understand. --Rob Pike
------------------------------
Date: 17 Sep 1999 15:40:35 +1000
From: Michael Brader <mbrader@aurema.com>
Subject: Re: Can Perl talk to Javascript??
Message-Id: <qciu5ahz8s.fsf@swag.sw.oz.au>
Steven Smolinski <sjs@yorku.ca> writes:
> abigail@delanet.com (Abigail) writes:
>
> > wolflake (wolflake@xxorn.net) wrote on MMCCVI September MCMXCIII in
>
> > Of course, if JavaScript program is being run inside a wowser, you need to
> > figure out how to communicate with the wowser, not to JavaScript directly.
>
> I know I'll regret this, but I cannot resist. I'm familiar with the
> unfortunately-named "browser" family of applications; however, I've not
> encountered a "wowser." What is such a beast?
I think it might be an apt term for some of the "browser" vendors.
The term wowser- surely one of the most impressive and
expressive of Australian coinages - is used to express healthy
contempt for those who attempt to force their own morality on
everyone. The person who abstains from alcohol (for whatever
reason) is not thereby a wowser: s/he's just probably very
fit. But when s/he tries to force everyone else to do as s/he
does, then s/he is a wowser. Or as C.J. Dennis defines the term:
'Wowser: an ineffably pious person who mistakes this world for a
penitentiary and himself for a warder'.
(from: http://www.anu.edu.au/ANDC/Austwords/wowser.html)
--
Michael Brader
Aurema Pty Ltd (formerly Softway Pty Ltd)
PO Box 305, Strawberry Hills, NSW 2012, Australia
Email:mbrader@aurema.com, Tel: +61 2 9698 2322, Fax: +61 2 9699 9174
------------------------------
Date: 17 Sep 1999 05:47:49 GMT
From: neutron@fc.hp.com (Jack Applin)
Subject: Re: challenge results
Message-Id: <7rskm5$470$1@fcnews.fc.hp.com>
Jack Applin wrote:
> This one doesn't work, but I think it should:
> perl -0\\1pe '$_=rand>.5?uc:lc'
Matthew Bafford quoted perlrun(1) and wrote:
> \\1 isn't an octal number.
Thanks so much. The rest of my posting made it clear that I was proposing
an *extension* to the current -0 option. We all know that it doesn't
currently work this way. I was saying that it would be good if it *did*
work this way. Perhaps the phrase "I think it ought to" would have been
clearer to you than "I think it should".
-Jack Applin
neutron@fc.hp.com
------------------------------
Date: 17 Sep 1999 03:32:50 GMT
From: dpb@cs.brown.edu (Don Blaheta)
Subject: Re: CONTEST: Range Searching
Message-Id: <7rscp2$o3h@cocoa.brown.edu>
Quoth Kragen Sitaker:
> In article <7rrrc9$dj8@cocoa.brown.edu>, Don Blaheta <dpb@cs.brown.edu> wrote:
> > #patba
> > while (<>) {
> > shift @forelines if @forelines > $fore;
> > push @forelines, $_;
> > print and $aftleft-- and @forelines = () if $aftleft;
> > print @forelines and $aftleft = $aft if /$pat/o;
> > }
>
> This is the one I had the most trouble with, mostly avoiding the
> overlap.
>
> What happens here if $aft is 0 and we get two sequential input lines
> with the pattern?
Ah, hadn't tried an aft of 0. I'll check it out next time I'm at my
regular node.
> I notice you're not using strict.
I did in my test program, and it worked except that the variables needed
to be declared, e.g. with
use vars qw(@forelines $fore $aftleft $aft $pat %opt)
I left it out of the submitted program to avoid visual clutter.
> >> * time efficiency: is your solution fast?
> >
> >Hard to say until I have something to test it against. I think I at
> >least avoided anything excruciatingly _slow_.
>
> I'll test it against mine when I have the time :)
<grin>
--
-=-Don Blaheta-=-=-dpb@cs.brown.edu-=-=-<http://www.cs.brown.edu/~dpb/>-=-
QUE SERA SERF
Life is feudal
------------------------------
Date: 16 Sep 1999 22:56:35 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: CONTEST: Range Searching
Message-Id: <37e1ca03@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
dpb@cs.brown.edu (Don Blaheta) writes:
:Quoth Tom Christiansen:
:> 3) Write a "patba" program that prints out up to
:> X lines before the match and Y lines after the match.
:>
:> patba [-A X] [-B T] pattern [files ...]
:
:This isn't consistent with itself or the previous two items; I assumed
:-A to indicate "after" and -B "before" as with the previous two.
Yes, that's right. I typed it wrong. I'm just emulating gnu grep.
Think of it as
patba [ [ [-A X] [-B Y] ] | [-C N] ] pattern [files ...]
but that's a bit harder to explain.
--tom
--
If you still want to do this in light of the above disadvantages, the method
is left as an exercise to the reader. It'll void your Apache warrenty,
though, and you'll lose all accumulated Unix guru points.
-- FAQ for Apache
------------------------------
Date: 16 Sep 1999 23:00:31 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: CONTEST: Range Searching
Message-Id: <37e1caef@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc, Michael de Beer <madebeer@igc.apc.org> writes:
:Any restrictions on system calls?
Ah, I don't explain you doing an
exec 'gnugrep', @ARGV;
It's the algorithm(s) that I want good but concise examples of, because
people will use this in other situations than simply greppish examples of.
I was only showing the -A, -B, and -C flags because I thought they'd
trigger associations with the samely-named gnugrep options.
--tom
--
"Even egotists are allowed to have opinions." --Larry Wall
------------------------------
Date: 16 Sep 1999 23:03:29 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: CONTEST: Range Searching
Message-Id: <37e1cba1@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc, abigail@delanet.com writes:
:If the match appears on line N + 3, does that mean one has to print
:lines 1 .. N, and line N + 3, or lines 3 .. N + 3?
:
:What if there's no match at all?
Sorry that I missed your posting. My killfile seems to have zapped my
own stuff this time. Odd.
What I think I mean is that the -B3 should act the way gnugrep's does:
when you find a match, pretty much you print the matching line and the
three lines previous to it. I'm just trying to get good examples
of the general algorithms involved here to add to the FAQ so that
people can use them in various programs.
--tom
--
My opinions may have changed, but not the fact that I am right.
-- Ashleigh Brilliant
------------------------------
Date: 16 Sep 1999 22:54:22 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: CONTEST: Range Searching
Message-Id: <37e1c97e@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc, Lewis Perin <perin@panix.com> writes:
:Perhaps it was deliberate, but the above code doesn't snag the second
:pair if it overlaps with the first, as in
:
:YIN
:YANGYIN
:YANG
No, it wasn't really deliberate. My test cases weren't good enough
to catch that.
--tom
--
"Politics is a pendulum whose swings between anarchy and tyranny are fueled by
perennially rejuvenated illusions."
- Albert Einstein
------------------------------
Date: 17 Sep 1999 01:58:55 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: CONTEST: Range Searching
Message-Id: <x7hfkuhye8.fsf@home.sysarch.com>
>>>>> "DB" == Don Blaheta <dpb@cs.brown.edu> writes:
DB> Here are the three while loops comprising the brunt of my programs:
DB> while (<>) {
DB> shift @forelines if @forelines > $fore;
DB> push @forelines, $_;
DB> print @forelines and @forelines = () if /$pat/o;
DB> while (<>) {
DB> shift @forelines if @forelines > $fore;
DB> push @forelines, $_;
DB> print and $aftleft-- and @forelines = () if $aftleft;
DB> print @forelines and $aftleft = $aft if /$pat/o;
well, what happens when you have multiple files and a match is at the
end of the previous file? i think you will print the next N lines from
the next file since you have a single global <> loop. and if that is all
your loop will be, you could out the @ARGV stuff in a BEGIN block and
wrap the code in a -n loop.
i am working on version which will do all 3, handle the
EOF problem as well as have a -O option to do overlaps, all in a single
program. wish me luck and tuits.
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: Fri, 17 Sep 1999 01:21:34 -0400
From: "bob" <zorgok@flashmail.com>
Subject: help!
Message-Id: <DhkE3.1427$z5.44488@ndnws01.ne.mediaone.net>
i know this isn't a perl question...
well, it sorta is.
it's perl-driven....
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!
email(brsullivan@mediaone.com) aol screen name(bobx11)
thanks anyone
------------------------------
Date: Fri, 17 Sep 1999 11:55:41 +0800
From: "Daniel Y.L." <linyong2000@990.net>
Subject: Re: Help: No pipe output.
Message-Id: <7rse4p$emr$1@news.ntu.edu.sg>
Hi,
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.
Kragen Sitaker <kragen@dnaco.net> wrote in message
news:rv6E3.14433$N77.1067283@typ11.nn.bcandid.com...
> In article <7rqrcc$80c$1@news.ntu.edu.sg>,
> Daniel Y.L. <linyong2000@990.net> wrote:
> >#$glim is a correct command: glim -i -F 'a.dat' '{artist;title}';
> >open (PIPEGLIM, "$glim|") || die "Cannot open pipe";
> >
> >print "glim begins output:\n";
> >while (<PIPEGLIM>) {
> > print "glim result:$_\n";
> >}
> >close (PIPEGLIM);
> >
> >The C program is located in the same directory as my Perl/CGI program and
> >changed mode to 5755 (chmod 5755 glim). When I use web browser to run my
> >CGI program, there is no output from glimpse (but, I can see the string
> >before the while loop). Could you give me any help? Thank you very
much.
>
> 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.
> --
> <kragen@pobox.com> Kragen Sitaker
<http://www.pobox.com/~kragen/>
> Tue Sep 14 1999
> 55 days until the Internet stock bubble bursts on Monday, 1999-11-08.
> <URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: 17 Sep 1999 01:12:24 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: How can I know if string have points?
Message-Id: <x7ogf2i0jr.fsf@home.sysarch.com>
>>>>> "KS" == Kragen Sitaker <kragen@dnaco.net> writes:
KS> In article <37E162E8.6B57EE98@mail.cor.epa.gov>,
KS> David Cassell <cassell@mail.cor.epa.gov> wrote:
>> Kragen Sitaker wrote:
>>> _Picking Up Perl_, on the Web at http://www.ebb.org/PickingUpPerl/,
>>
>> Ummm Kragen, I just took a quick glance, and the first thing I
>> noticed is that the author refers to the construct <STDIN> as
>> a filehandle, rather than an operator working on a filehandle.
>> I stopped reading at that point.
KS> Yow. I didn't read that far :)
no wonder. it is very verbose. i quick scan found many other problems.
<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.
here is another goof:
<quote>
There a few characters in single quoted strings that do not always
represent themselves.
</quote>
well he covers \\ and \` but those are the only 2 special cases of
single quotes. not 'a few', just 2!
<quote>
'This is my string; # ILLEGAL: missing close ' before ;
</quote>
that is illegal because the string ends with the ' before the illegal
unknown token "before". not a good comment as this has nothing to do
with ;
<quote>
Notice that the \n character moves the cursor to the beginning of the
next line. On some systems (such as Microsoft systems), this can
translate into some sequence of ASCII characters. However, all Perl
programs need only use the \n sequence to move to the next line,
regardless of what sequence of characters are "truly" needed to move to
the next line.
</quote>
that is confusing at best, wrong at worst. \n is just \n in perl. only
on i/o might it get translated by the stdio if binmode is not
enabled. and discussing cursor location at this intro level is veering
off topic. files use lines too and need newlines.
<quote>
Note that if, for any reason, you need integer-only calculations for all
mathematical operations, you can use the pragma use integer;, which
forces integer operations in all cases. Be careful with this pragma,
however, because placing it in a program can drastically change the
manner in which your program operates!
</quote>
so how come none of these drastic changes in numeric calculations are
mentioned anywhere? this is the only place i found use integer.
<quote>
print "${owner}'s dog, $dog, ate $amount pounds of $what.\n";
You may have noticed by now that we did something very odd with $owner
in the example above. Instead of using $owner, we used ${owner}. We were
forced to do this because following a scalar variable with the character
' would confuse Perl. To make it clear to Perl that we wanted to use the
scalar with name owner, we needed to enclose owner in curly braces
({owner}).
</quote>
so why is a ' not good after a scalar var? i know that it is the old
package separator but it should be mentioned at least in a footnote.
here is a real dumb thing. he calls arrays "list variables"!!
here is another bad one:
<quote>
Lists as Queues
If we can do stacks, then why not queues? This is what shift and unshift
do. The names are an artifact of the Unix shells that used them to
"shift around" incoming arguments. However, if you think of the shift
function as "dequeue" and the unshift function as "enqueue", you can see
how they work just like queues. Here is a mirror example to the one we
used for stacks:
</quote>
queues have data entered on one end and removed from the other. the
proper pairs should be push and shift, and unshift and pop. his queue is
really just a stack working from the lower end of the array (NOT A LIST!!)
here is a fun bug:
</quote>
Expression Context Variable Evaluates to
Referred To
@list scalar @list, a list the total number of
elements in @list
(same as $list[$#list] + 1)
</quote>
isn't that expression fun? also @list is an ARRAY NOT A LIST!!!
enough for now. this was not a fine tooth comb review but a fairly fast
scan. if i cared to i am sure i would find many more bugs. but the list
vs. array thing pervades the document which makes me not want to do any
more bug searching.
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. and the author needs to learn what features are
important and which are not (e.g. mentioning use integer but nothing
about q, qq and here docs). and he needs a lobotomy to remove the
concept that @array is a list.
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: Thu, 16 Sep 1999 23:36:51 -0500
From: Mike Stone <mike@yawp.com>
To: Kragen Sitaker <kragen@dnaco.net>
Subject: Re: Lambda calculus stuff in Perl
Message-Id: <Pine.NEB.3.96.990916190843.18598B-100000@www.yawp.com>
> >again, switching on classname is generally a weak solution. it's far
> >better to define your class interfaces in a way that makes such switching
> >unnecessary.
>
> I'm interested what you think about the lambda-calculus code I posted
> yesterday. Some of it does both -- whichever seemed more sensible.
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.
lessee.. >clickety click<
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. if
you're working with an NFA, you get scan-and-backtrack delays, but those
are still O(n). if you're looking at a simple language (no
e-transitions), parsing really boils down to a single pass over the
sequence of input characters, with some funky things happening in the
background. unless you've done something especially wierd with your
parsing, and that's harder than it sounds if you get something that
actually works, it should follow the same model.
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.
here we go.. the BNF for the language definition.. seems straightforward
enough. and here are some top-level parsing routines. yep..
top-downer. hmm..
a tip, FWIW: you're prescanning the input in your top-level routine, to
decide which of the parse routines at the next level to call. that
works for a simple grammar of the type you've defined, but can break for
more complex grammars. 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. 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:
sub parse_token {
my $string = shift;
my ($bool, $rest) = ();
($bool, $rest) = &parse_lambda ($string);
return ($rest) if ($bool);
($bool, $rest) = &parse_app ($string);
return ($rest) if ($bool);
($bool, $rest) = &parse_varref ($string);
return ($rest) if ($bool);
#report an error, because nothing matched#
}
of course, for such occasions, i prefer to turn the lower level parsers
into objects to make iteration easier:
@EXPR = ();
push @EXPR, new expr_parser;
push @EXPR, new app_parser;
push @EXPR, new varref_parser;
sub parse_expr {
my $string = shift;
my ($bool, $rest) = ();
for $item (@EXPR) {
($bool, $rest) = $item->parse ($string);
return ($rest) if ($bool);
}
#report an error, because nothing matched#
}
and looking at the substitution code, you seem to be building the parse
tree using the objects being parsed.. fair enough.
oh, ick.. i'm afraid i don't think much of this, though:
> return (new lambda(
> $newvar,
> $self->[1]->substitute(
> new varref($newvar),
> $self->[0]
> )->substitute($replacement, $var)
> ))
give us a coupla temp variables there, wouldja luv? passing (the output
of a function called from (the output of another function using (the
output of yet another function) as a parameter)) as a parameter is just a
tad on the hard-to-read side. not exactly prime instructional code,
there. ;-)
.. besides, the optimizer will probably do all that for you, so you don't
gain much in exchange for the brain cells you'd murder trying to find a
typo in that monster.
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?
ouchie.
that's certainly doable, and is rather elegant at the object level, but
it's pretty hardcore. i'm more accustomed to building a parser which
models the language, takes a character stream as input, and returns a
parse tree as output. the parser's structure remains constant for the
life of the program, and the parse tree is more or less independent of the
input stream, aside from being isomorphic in structure. not having to do
as many things at once makes the overall code less brain-bending.
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:
$DEPTH = 0;
sub random_expr {
my $r = rand;
my @vars = ('a'..'z');
my $expr = undef;
$DEPTH++;
if ((10 < $DEPTH) || ($r < 0.3)) {
$expr = new varref ($vars[int rand @vars]);
} else {
$expr = ($r < 0.5) ? new app (random_expr, random_expr) :
new lambda ($vars[int rand @vars], random_expr);
}
$DEPTH--;
return ($expr);
}
the trick of using return()s to short-circuit your switch()-equivalent
just didn't leave you enough elbow room for anything else. normally, i'd
say it was just something you missed on the fly, but since you immediately
went on to spend about 20 trying to calculate the probability of
termination, i'm gonna fine you a tap on the pinky. ;-) before you haul
out the probability, spend some quality time with your booleans.
oh yeah.. and a tap on the other pinky for reducing the convergence of an
infinite series to a simple quadratic. ;-)
what you need is the sum of the probabilities, as N goes to infinity, that
random_expr() will terminate on the Nth recursion. at each pass, the
probability of hitting varref immediately, or a nonterminal composed
entirely of varrefs, is .3 + .2*(.3**2) + .5*(.3) == .468. the
probability of hitting a nonterminal composed entirely of nonterminals is
.2*(.7**2) + .5*(.7) = .448. the probability of getting a nonterminal
whose contents are mixed is 2*(.2*(.3 * .7)) == .084. those add up to 1,
so we know we haven't hopped off the clue train so far.
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:
N P
---------
1 .468
2 .717
3 .849
4 .920
5 .957
10 .998
25 .999999859
the odds of recurring until memory overflow are, shall we say, vanishingly
small.
of course, that's moot now. ;-)
offhand, do you have a copy of the "Gang of Four" book[1]? 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.
[1] - _Design Patterns_, Gamma, et al.
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.
--
mike
------------------------------
Date: 16 Sep 1999 22:19:59 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Parsing Tab Delimited File
Message-Id: <slrn7u3cvu.vd4.abigail@alexandra.delanet.com>
Kragen Sitaker (kragen@dnaco.net) wrote on MMCCVIII September MCMXCIII in
<URL:news:GzgE3.15286$N77.1148204@typ11.nn.bcandid.com>:
[] In article <slrn7u2kj1.vd4.abigail@alexandra.delanet.com>,
[] Abigail <abigail@delanet.com> wrote:
[] >Bullocks. If a split would suffice, the format is too restrictive. CSV files
[] >aren't there to satisfy the programmer. They are there for the user. And if
[] >a programmer complains it's too hard to parse them - boohoo, fire him, and
[] >get a better programmer.
[]
[] Most cases I've seen CSV used, it's been for transfer from one program
[] to another -- not human entry or human reading.
[]
[] Agreed, though, that programmers program to serve users.
[]
[] >Too make them useful. Other techniques could have been used as well, but
[] >then you still won't be able to parse them with just a split.
[]
[] 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?
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: 17 Sep 1999 03:56:08 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: perl equivalent of a Unix command line sort?
Message-Id: <7rse4o$b24@dfw-ixnews6.ix.netcom.com>
Jim Hutchison (jimhutchison@metronet.ca) wrote:
: According to your paper, the Unix sort is much better for huge files,
: which is too bad 'cause I prepfer to use just Perl. I've had to
: resort to it on a Sun E-450 box with 786 mb of memory!!
Preference is all well and good, but not when it turns into dogma.
Sorting huge files is a very specialized task and writing code to do it
requires specialized knowledge and experience; the "obvious" ways to do it
don't scale well. IOW, it is the sort of task that should be accomplished
by a purpose-built tool if one is available. In your case one is.
------------------------------
Date: 17 Sep 1999 03:48:47 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Problem with open() and probably something else
Message-Id: <7rsdmv$b24@dfw-ixnews6.ix.netcom.com>
David Wall (darkon@one.net) wrote:
: sub WriteIndex {
: my $id;
: # open MSGS, ">$dir/$dbname" or die("Cannot open $dir/$dbname for writing:
: $!\n");
: #flock MSGS, 2 unless $nolock;
: truncate MSGS, 0;
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).
: # stuff to print the data to the file.....
: }
: close MSGS or die("Error closing $dbname: $!\n");
: }
:
: For some reason I don't understand, the MSGS file ends up completely blank!
: Can't I open a file in one subroutine and expect to use the same filehandle in
: another subroutine? I've certainly done it before.....
------------------------------
Date: 17 Sep 1999 03:39:17 GMT
From: rong@news.pgs.com (Ron Grunwald-Computer Programmer PGS Tensor Perth)
Subject: Re: Reading symbolic links
Message-Id: <7rsd55$5ca$1@news.hstn.tensor.pgs.com>
Ron Grunwald-Computer Programmer PGS Tensor Perth (rong@news.pgs.com) wrote:
: Hello all Perlers,
: I have a simple question to which there is probably a simple answer,
: but I couldn't find any answers from the FAQ or the Perl documentation.
: I intend to scan through a specified filesystem using the File::Find
: module and collect all the symbolic links encountered. The question is,
: when a symbolic link is found, how can one determine which file or
: directory it is pointing to ?
: I was hoping that using lstat() could get me the answer, but I've hit
: a dead end instead.
: Any suggestions ?
: Cheers, Ron.
Well, looks like I've found the answer myself. readlink() does what I'm
after. So, my code looks something like this:
--------------------------------------------------------------------------
use strict;
use File::Find;
my $rootDir = '/usr3/slack-4.0';
find (\&wanted, $rootDir);
sub wanted {
if (-l $_) {
print ("Found: $_ -> ", readlink ($_), "\n");
}
}
--------------------------------------------------------------------------
Ron Grunwald | Usual E-mail rong@prth.pgs.com
UNIX Programming Section | Alternate E-mail r.grunwald@usa.net
PGS Tensor Pty. Ltd. | Work Tel. 011 618 9320 9029
Petroleum Exploration and | IBM Centre, Perth
Seismic Processing. | Western Australia
--------------------------------------------------------------------------
------------------------------
Date: 17 Sep 1999 03:28:51 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: references in dbms
Message-Id: <7rschj$b24@dfw-ixnews6.ix.netcom.com>
Todd Smith (todds@infotraxsys.com) wrote:
: I'd like to store complicated data structures, such as lots of
: references inside references, into a db file. Is there any way to do it?
Yes, using the MLDBM module, which will serialize your data structures
when storing entries and deserializing them when fetching entries. You
get a choice of serialization techniques; you'll probably want to choose
Storable rather than the default of Data::Dumper for speed and space
reasons (though there are tradeoffs with all the techniques).
------------------------------
Date: 16 Sep 1999 22:25:08 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Two dimensional array
Message-Id: <slrn7u3d9h.vd4.abigail@alexandra.delanet.com>
Tim (bie@connect.ab.ca) wrote on MMCCVII September MCMXCIII in
<URL:news:37E13C9E.53D8@connect.ab.ca>:
~~ I wasn't sure, I was offering a thought.
~~ You people are so picky about what gets posted in here, u post more
~~ about what not to post then you do quality posts.
Jeopardy style, sigquoting, k3wlt0k.
3 strikes, and you're out.
*plonk*
Abigail
--
perl -wlne '}for($.){print' file # Count the number of lines.
-----------== 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 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 826
*************************************