[8750] in Perl-Users-Digest
Perl-Users Digest, Issue: 2368 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 21 02:07:40 1998
Date: Mon, 20 Apr 98 23:02:30 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 20 Apr 1998 Volume: 8 Number: 2368
Today's topics:
Re: Perl installation failure - cannot use chmod on dir plambert$1@plambert.org
Re: Perl installation failure - cannot use chmod on dir (Martien Verbruggen)
Perl Modules <snx@snx.com>
Re: Perl Modules (Tad McClellan)
Re: Perl Modules (Craig Berry)
Re: rand($.) (was wc-l in Perl) (Abigail)
Re: Regexp question <bmb@ginger.libs.uga.edu>
Re: Regexp question <merlyn@stonehenge.com>
Re: Regexp question <rjk@coos.dartmouth.edu>
Re: Regexp question (Tad McClellan)
Re: Regular Expression to match a valid IP address <rjk@coos.dartmouth.edu>
Re: Regular Expression to match a valid IP address <rjk@coos.dartmouth.edu>
Re: Regular Expression to match a valid IP address <flavell@mail.cern.ch>
Re: suggested research methods? <sneaker@earthling.net>
Re: UNIX mail script plambert$1@plambert.org
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Apr 1998 20:44:36 GMT
From: plambert$1@plambert.org
Subject: Re: Perl installation failure - cannot use chmod on directory
Message-Id: <6hgc3k$mch$1@nntp1.ba.best.com>
Charles R. Thompson <newscatcher@greenville2000.com> spewed:
> Has anyone out there had experience with Telnet and a Best.com server? I am
> remotely helping someone install a script, and he seems to not be able to
> use chmod on his subdirectories. Being rather new to Telnet myself, have I
> missed something? I can do it fine on my servers.
> Is there some optional flag that must be set?
> Reply by email please if possible.
Replying by email is quite possible, but I'm not gonna. ;-)
Post your question to best.unix. I'll answer it there. And I still won't
reply by email. ;-)
--Paul L.
------------------------------
Date: 21 Apr 1998 03:01:55 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Perl installation failure - cannot use chmod on directory
Message-Id: <6hh273$q8c$2@comdyn.comdyn.com.au>
In article <6he9sv$sk8@bgtnsc02.worldnet.att.net>,
"Charles R. Thompson" <newscatcher@greenville2000.com> writes:
> Has anyone out there had experience with Telnet and a Best.com server? I am
> remotely helping someone install a script, and he seems to not be able to
> use chmod on his subdirectories. Being rather new to Telnet myself, have I
> missed something? I can do it fine on my servers.
This doesn't have anything to do with perl. Even though perl scripts
can be chmod-ed, so can text files, graphics files, and basically
every other file you can think of.
If you know how to use chmod, but are having problems with a certain
provider, contact them, or read the man pages on that system. If you
have doubts on how to use it, ask in one of the unix groups, or read
the man pages on the system.
> Is there some optional flag that must be set?
We don't even know what you're trying to do.
Check the man page.
# man chmod
> Reply by email please if possible.
Nope. Post here, read here. Besides, your post is very much off-topic.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | In a world without fences, who needs
Commercial Dynamics Pty. Ltd. | Gates?
NSW, Australia |
------------------------------
Date: Mon, 20 Apr 1998 15:47:31 -0400
From: Stacy Hunter <snx@snx.com>
Subject: Perl Modules
Message-Id: <353BA63B.CA0D2FA1@snx.com>
I am trying to use a perl module and have correctly installed it in a
local directory.
However, I am not sure how to implement it into my script.
I have:
#!/usr/bin/perl -w
use lib /local/path;
use Date::Format;
and keep getting the error message Search pattern not terminated at
test3.pl line 4.
Argh.
Stacy
------------------------------
Date: Mon, 20 Apr 1998 15:50:16 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Perl Modules
Message-Id: <8ecgh6.hp1.ln@localhost>
Stacy Hunter (snx@snx.com) wrote:
: I am trying to use a perl module and have correctly installed it in a
: local directory.
: However, I am not sure how to implement it into my script.
: I have:
: #!/usr/bin/perl -w
: use lib /local/path;
use lib '/local/path';
: use Date::Format;
: and keep getting the error message Search pattern not terminated at
: test3.pl line 4.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 20 Apr 1998 21:21:05 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Perl Modules
Message-Id: <6hge81$629$4@marina.cinenet.net>
Stacy Hunter (snx@snx.com) wrote:
: #!/usr/bin/perl -w
: use lib /local/path;
: use Date::Format;
:
: and keep getting the error message Search pattern not terminated at
: test3.pl line 4.
I'll bet you left out a couple of lines. You need to quote '/local/path',
which apparently looks like a search pattern // to your version of Perl.
Mine (the latest) also dies, but with a different error, when presented
with this input.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 20 Apr 1998 21:09:56 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: rand($.) (was wc-l in Perl)
Message-Id: <6hgdj4$m8i$1@client2.news.psi.net>
John Blanco (johnnie@holly.colostate.edu) wrote on MDCXCIII September
MCMXCIII in <URL: news:353B7CB0.49612DF@holly.colostate.edu>:
++ Tom Mornini wrote:
++
++ > In a discussion about picking a random line from a file Tom Phoenix
++ > wrote:
++ >
++ > > open FILE, $name or die "Can't read '$name': $!";
++ > > while (<FILE>) {
++ > > $line = $_ if rand($.) <= 1;
++ > > }
++ > > print "One randomly-selected line is $line";
++ >
++ > My question is: Why doesn't this hopelessly bias the randomness
++ > towards
++ > the beginning of the file, when rand($.) would be more likely to be <=
++ > 1?
++ >
++
++ Instead of testing the program by finding the line it chooses, adjust
++ the script so it prints each line number it ever does choose. In a
++ sample run on a 964 line file my results were:
++
++ Line 1 Chosen!
++ Line 2 Chosen!
++ Line 4 Chosen!
++ Line 7 Chosen!
++ Line 15 Chosen!
++ Line 66 Chosen!
++ Line 131 Chosen!
++ Line 253 Chosen!
++ Line 374 Chosen!
++ Line 544 Chosen!
++
++ As you can see, and as everyone else said, it is MUCH more likely to
++ choose a line early on in the file than later -- however, the line you
++ end up with, nameley 544 in this case, is usually what is chosen because
++ it will end up being the "dark horse" pick that became the last
++ selected.
Instead of guessing, or running tests, how about a _proof_ the above
algorithm is correct?
Theorem: Tom's algorithm to pick a random line from the file is fair.
Proof: With induction over the number of lines in the file.
Let P(n) be "Tom's algorithm is fair for a file with n lines".
Clearly, P(1) is true.
Now assume P(n) is true for all P(i), i <= 1 <= n.
We will prove the correctness of P(n+1).
Tom's algorithm applied to a file with n+1 lines will return
the last line with probability 1/(n+1), or with probability
n/(n+1), it will return a random line out of the first n lines.
But according to the hypothesis, the algorithm is fair for a
file of n lines. Hence, any line out of n lines will be selected
with probability 1/n. Hence, when applied on n+1 lines, the last
line is selected with probability 1/(n+1), or any of the first n
lines is select with probability 1/n * n/(n+1) == 1/(n+1).
But that means the algorithm is fair for n+1 lines.
Conclusion: The algorithm given by Tom to randomly select a
a line from a file is fair.
Abigail
--
perl -wle 'print "Prime" if ("m" x shift) !~ m m^\m?$|^(\m\m+?)\1+$mm'
------------------------------
Date: Mon, 20 Apr 1998 16:25:21 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Regexp question
Message-Id: <Pine.A41.3.96.980420161850.29882C-100000@ginger.libs.uga.edu>
(^|\s) matches the beginning of the string, or one whitespace character
(\s|$) matches one whitespace character, or the end of the string
I don't see anywhere that says these do what you say below.
Ah, they may be messy, but you'll come to love them (well ... love/hate,
maybe).
HTH, Brad
On Mon, 20 Apr 1998, A.P. wrote:
> I'm learning Perl reading the Llama book. There's an exercise proposing
> to find a regexp to match the same word written two or more times in a
> row (with possibly varying intervening whitespace). The book proposes
> the following answer:
>
> /(^|\s)(\S+)(\s+\2)+(\s|$)/
>
> Why do (^|\s) and (\s|$) match any number of leading/trailing
> whitespaces and not just one or none?
> It's a really messy one this regexp business!!
> Thanks a lot.
>
>
>
----------------
Brad Baxter, UGA
------------------------------
Date: Mon, 20 Apr 1998 20:35:18 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
To: "A.P." <road@apdo.com>
Subject: Re: Regexp question
Message-Id: <8cu37o5j1b.fsf@gadget.cscaper.com>
>>>>> "A" == A P <road@apdo.com> writes:
A> I'm learning Perl reading the Llama book.
Good choice! (But some would accuse me of unfair bias on that issue.)
A> There's an exercise proposing
A> to find a regexp to match the same word written two or more times in a
A> row (with possibly varying intervening whitespace).
Yes. Chapter 7, exercise 1, part f, if I recall (without looking).
A> The book proposes
A> the following answer:
A> /(^|\s)(\S+)(\s+\2)+(\s|$)/
A> Why do (^|\s) and (\s|$) match any number of leading/trailing
A> whitespaces and not just one or none?
Uh... they don't. :-) the \s there matches just one space. But
you need only one to have "at least one". :-)
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 133 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Mon, 20 Apr 1998 16:33:38 -0400
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: Regexp question
Message-Id: <353BB12A.281AB342@coos.dartmouth.edu>
A.P. wrote:
>
> I'm learning Perl reading the Llama book. There's an exercise proposing
> to find a regexp to match the same word written two or more times in a
> row (with possibly varying intervening whitespace). The book proposes
> the following answer:
>
> /(^|\s)(\S+)(\s+\2)+(\s|$)/
>
> Why do (^|\s) and (\s|$) match any number of leading/trailing
> whitespaces and not just one or none?
They don't. As you thought they should, (^|\s) and (\s|$) *do* only match one
whitespace or none (at the beginning or end of the string). (Note the
difference between (^\s) and (^|\s). One matches a whitespace character at
the beginning of the string. The other matches the beginning of the string
*or* a whitespace character.)
To show you what is happening, consider this line:
" foo foo " =~ /(^|\s)(\S+)(\s+\2)+(\s|$)/;
Here's what happens:
Pos 1) The regex engine tries to match ^. ^ matches, so the rest of the
alternation is put aside. Now the engine tries to match \S+ starting at the
first space. The match fails. Now the engine remembers the alternation and
tries the second part instead. \s matches the first space. The engine tries
to match \S+ starting at the second space. It still fails, and the engine is
out of options at this position.
So, the regex engine tries to match the regex starting at the second position
in the string.
Pos 2) The regex engine tries to match ^, which fails. Now the engine tries
to match \s, which matches the second space. The engine tries to match \S+,
starting at the letter f. \S+ matches 'foo', and then \s+\2 matches ' foo'.
Now the engine tries to match \s, which matches the second to last space. The
rest of the alternation is put aside, and that's the end of the regex. So,
the entire regex matched ' foo foo ' and the engine returns success.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J. Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Mon, 20 Apr 1998 16:05:18 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Regexp question
Message-Id: <eadgh6.bu1.ln@localhost>
A.P. (road@apdo.com) wrote:
: I'm learning Perl reading the Llama book. There's an exercise proposing
: to find a regexp to match the same word written two or more times in a
: row (with possibly varying intervening whitespace). The book proposes
: the following answer:
: /(^|\s)(\S+)(\s+\2)+(\s|$)/
: Why do (^|\s) and (\s|$) match any number of leading/trailing
: whitespaces
They do _not_ match any number (and they don't need to for the
match to "succeed", they just need to match a substring of the
string being searched).
: and not just one or none?
They do match only one or none.
: It's a really messy one this regexp business!!
$_ = ' llama llama ';
^^^^^^^^^^^^^
That underlined part matches (using the \s alternative at each end).
The first and last spaces are not part of the substring that matched.
The given regex _does_ match a substring, and has not been written
is such a way that it requires that the _entire_ string matches.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 20 Apr 1998 15:59:05 -0400
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: Regular Expression to match a valid IP address
Message-Id: <353BA910.686D1CB9@coos.dartmouth.edu>
Fritz Knack wrote:
>
> m#(\d)+.(\d)+.(\d)+.(\d)+#
The pluses should be inside the parentheses. Otherwise, $1, $2, etc., will
only contain the last digit of each number. And don't forget ^ and $.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J. Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Mon, 20 Apr 1998 16:06:08 -0400
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: Regular Expression to match a valid IP address
Message-Id: <353BAAB7.61A80DFF@coos.dartmouth.edu>
IP: {
last IP if $ip =~ /[^\d.]/;
@pieces = split /\./, $ip;
last IP if @pieces != 4;
last IP if $pieces[0] < 1 or $pieces[0] > 254;
last IP if $pieces[1] < 0 or $pieces[1] > 255;
last IP if $pieces[2] < 0 or $pieces[2] > 255;
last IP if $pieces[3] < 1 or $pieces[3] > 254;
print "ip '$ip' is valid\n";
}
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J. Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Mon, 20 Apr 1998 22:45:08 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Regular Expression to match a valid IP address
Message-Id: <Pine.A41.3.95a.980420224216.76424S-100000@rsplus07.cern.ch>
On Mon, 20 Apr 1998, Ronald J Kimball wrote:
> IP: {
> last IP if $ip =~ /[^\d.]/;
> @pieces = split /\./, $ip;
..
> last IP if $pieces[1] < 0 or $pieces[1] > 255;
I'm sure I'm going to regret this, but how can a string consisting only
of digits possibly test less than 0?
------------------------------
Date: Mon, 20 Apr 1998 21:07:44 GMT
From: Bill 'Sneex' Jones <sneaker@earthling.net>
Subject: Re: suggested research methods?
Message-Id: <353BB783.7732D9B6@earthling.net>
John Porter wrote:
> > I try to 'read' CPAN as often as possible...(I printed out the 'long'
> > version...)
>
> YOU PRINTED IT OUT?
> What in hell would possess someone to do something so stupid?
> It strips the document of almost all of its usability: you can't
> do text searches within it, you can't follow links from it, and
> it doesn't automagically get updated.
To each his own. Study your way, I'll study mine.Besides, what the hell else
am I gonna read
while taking a crap?! :D
> > Also, I believe I saw a Perl Developers
> > book by Jon Orwant(?) listed every
> > Module in existince... $34.95
> > I believe, published by Active Press(?)
>
> With all due respect to Jon, this suffers the same problems as
> printing out the CPAN long listing yourself. It's not quite as
> bad, since it includes short usage statements.
Jon didn't place the ENTIRE book on-line did he?
> > otherwise
> > rip the Modules apart and tinker with them.
>
> I have never had to do this.
> (Sure, I've done it for fun, but that's not the same thing.)
>
> John Porter
Not eveyone here can be as clairvoyant as you :-)
:-)
__________________________
Bill Jones...............|
Sneaker's Nest...........|
Chasecreek Systemhouse...|
------------------------------
Date: 20 Apr 1998 20:49:22 GMT
From: plambert$1@plambert.org
Subject: Re: UNIX mail script
Message-Id: <6hgcci$mch$2@nntp1.ba.best.com>
anpap@usa.net spewed:
> I need a Unix (or perl) cgi script that will enable me to
> send mail without a mail client.
> I have tried telneting on port 25 from within a shell cgi
> script, but it didn't work.
> Anyone has a script that works??
Wow. I don't think anyone has _ever_ tried to do this before. If this
were a simple and common question (like "I can't get perl 5.004 to compile
under Unicos 9.0 with MLS enabled) it would be in many FAQs and answered
hundreds of times in Deja News and similar places. In fact, the answer
would be _so_ common and prevalent that posting to a newsgroup asking for
it would be rather like asking a librarian behind the library desk for
directions to the library.
But no, I don't think anyone has ever done this before. You're probably
on your own.
--Paul L.
[Sorry. Haven't had enough caffeine today. ;-) This translates roughly
to: Please read the Frequently Asked Questions lists and the other
documentation at your disposal. It's amazing what you'll find there.]
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 2368
**************************************