[8274] in Perl-Users-Digest
Perl-Users Digest, Issue: 1891 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 13 15:08:02 1998
Date: Fri, 13 Feb 98 12:00:32 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 13 Feb 1998 Volume: 8 Number: 1891
Today's topics:
/usr/lib/dld.sl: Unresolved symbol: inet_ntoa <jfooken@csc.com>
Re: `-w' should warn on ({} + 0) <joseph@5sigma.com>
Re: A Pubilc Apology. <gbarr@ti.com>
Basic File Manipulation (KHeise)
Re: Clearing all variables <elaine@lainer.com>
clpm.moderated: Ideas about automoderation <jason@primal.ucdavis.edu>
Re: ENCTYPE="multipart/form-data" QUESTION?!? <Luc.VanLinden@esat.kuleuven.ac.be>
Re: FAQless Forays (was: Code Example Needed) <*@qz.to>
Re: Fork/Threads (Brett Slocum)
htpasswd <Luc.VanLinden@esat.kuleuven.ac.be>
Re: htpasswd (Ian Kallen)
Re: Killfile Triage (boar dome)
Re: Location: returns empty document? <schmitzp@no.spam.wxs.nl>
Re: Location: returns empty document? <schmitzp@no.spam.wxs.nl>
Re: on reading FAQs and gurus answering questions (Chris Benson)
Perl 5.003 and IIS on NT 4.0 <reza@avestec.com>
Re: Question concerning backreferences (Andrew M. Langmead)
Re: Question concerning backreferences <joseph@5sigma.com>
Re: Quickie: regexp for valid e-mail addresses <3.14@Math.MIT.edu>
Re: regexp: /^[800|888]/ vs. /^8[0{2}|8{2}]/ (Alan Schwartz)
Re: scope of $<digit> (Joe McMahon)
Re: So what about last summer's RFD? Let's go moderate (John Stanley)
Re: Tell me your programming highs! <hebert@cs.fsu.edu>
Re: The Young Man and the Beach <gbarr@ti.com>
Re: Tom wins flamer of the year award! (Billy Chambless)
Re: Variable interpolation or reference? <joseph@5sigma.com>
what does "deprecate" mean? (Kevin B Cohen)
Re: what does "deprecate" mean? <doug@tc.net>
Re: Year 2000 Compliance: Lawyers, Liars, and Perl <jrs@merlyn.demon.co.uk>
Re: Year 2000 Compliance: Lawyers, Liars, and Perl (Peter Seebach)
Re: Zero-width positive lookahead assertion Q <*@qz.to>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 13 Feb 1998 20:41:15 +0100
From: Jens Fooken <jfooken@csc.com>
Subject: /usr/lib/dld.sl: Unresolved symbol: inet_ntoa
Message-Id: <34E4A1DB.15E9AA00@csc.com>
Who can help ?
/usr/local/mrtg-2.5.1> ./mrtg mrtg.cfg
/usr/lib/dld.sl: Unresolved symbol: inet_ntoa (code) from
/opt/perl5/lib/PA-RIl
Abort(coredump)
Platform is HP-UX 10.20
Perl:
Characteristics of this binary (from libperl):
Built under hpux
Compiled at Dec 24 1997 15:05:42
@INC:
/opt/perl5/lib/PA-RISC1.1/5.00404
/opt/perl5/lib
/opt/perl5/lib/site_perl/PA-RISC1.1
/opt/perl5/lib/site_perl
------------------------------
Date: Fri, 13 Feb 1998 12:43:55 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: `-w' should warn on ({} + 0)
Message-Id: <34E4A214.3733407C@5sigma.com>
It's documented, or it used to be. Or at least I think that's
where I learned about it.
-joseph
Junio Hamano wrote:
>
> Perl 5.004_04 seems to silently coerce a reference into an
> integer, but I do not see this documented anywhere. I do not
> get any warning from the program below:
--
Joseph N. Hall, prop., 5 Sigma Productions mailto:joseph@5sigma.com
Author, Effective Perl Programming . . . . . http://www.effectiveperl.com
Perl Training . . . . . . . . . . . . . . . http://www.perltraining.com
------------------------------
Date: Fri, 13 Feb 1998 08:48:11 -0600
From: Graham Barr <gbarr@ti.com>
Subject: Re: A Pubilc Apology.
Message-Id: <34E45D2B.9960748E@ti.com>
Rich Grise wrote:
> Humility is NOT one of the most desired places on the
> planet, is it?
>
> Yes, I'm sorry, I beg your forgiveness, I was a fool, and
> that's the last time. OK?
It takes a great person to admit when they are wrong, especially
in public. I admire you for it and wish there were others like you
on this list.
--
Originality is the ability to conceal your source.
------------------------------
Date: 13 Feb 1998 19:18:02 GMT
From: kheise@aol.com (KHeise)
Subject: Basic File Manipulation
Message-Id: <19980213191800.OAA09979@ladder02.news.aol.com>
I am a new Perl user with some prior programming knowledge, and so far I just
love it. There are a couple of questions I have about manipulating and
outputting I have.
Background: I am dealing with very large, fixed length data files (500M+ -
1,000,000+ records (lines)).
Question 1: Luckily our company appends a CRLF (carriage-return line-feed) at
the end of each record (line) even though we don't really need it, so it has
been easy for me to isolate records (lines), but there are times when I wont
want to use the CRLF as a record delimiter. I will want to define the records
according to x number of bytes (i.e.record1 = byte 0 - 199, record2 = 200-399,
etc.). It seems like an easy problem, but I can't figure out a clean,
efficient, and **fast** to deal with a file in this manner.
Question 2: I want to reverse the lines in a large file.
(i.e. File = "AA""AB""AC""AD"- Reversed File = "AD""AC""AB""AA"). Is there an
easy way to do this? Remember, these files are pretty huge, so I can't simply
reverse the contents of a list(I think).
Question 3: How do you return the number of bytes in a file?
Any comments, code, advice, etc. would be greatly appreciated. I'm really
exited about Perl and I could use all the help I can get to improve my
programming skills.
Jay
e-mail addr - kheise@pgicompanies.com
------------------------------
Date: Fri, 13 Feb 1998 13:54:52 -0500
From: "Lainer" <elaine@lainer.com>
Subject: Re: Clearing all variables
Message-Id: <34e496d3.0@myth.vianet.on.ca>
Someone else was KIND enough to point me in the right direction politely and
I have subsequently learned a great deal from his willingness to help.
Why are some people so damned rude to others in here? Nowhere did I see in
the FAQ that you had to be an expert in Perl to post to this NG. Perhaps
you should refrain from posting replies if you can't take a lighter tone
with people and be a little more helpful.
Martien Verbruggen wrote in message <6bvuj0$ak4$3@comdyn.comdyn.com.au>...
>In article <34e33aa2.0@myth.vianet.on.ca>,
> "Lainer" <elaine@lainer.com> writes:
>> I am calling it as a separate executable using "require" at the end of
the
>> loop.
>
>Then you are NOT calling it as a seperate process. You would need
>system, exec, backticks or qx// for that.
>
>perldoc -f require
>
>Please read.
>Martien
------------------------------
Date: Fri, 13 Feb 1998 11:16:57 -0800
From: Jason Christian <jason@primal.ucdavis.edu>
Subject: clpm.moderated: Ideas about automoderation
Message-Id: <Pine.OSF.3.95.980213100519.10711C-100000@primal.ucdavis.edu>
If I were a Perly King, I would set up a (perhaps partial) automoderator,
call it savetc.pl, that would...
(1) Keep a (confidential) list of Registered Posters;
(2) Run an ace antispam machine;
(3) Handle (in conjuction with (1) and (2)) cc'ed replies to posted articles;
(4) Run a filter and autorespond for standard signs of cluelessness.
(1) Registered Posters.
When a post comes in, it gets a unique $id. Next, the From: field is
checked. If it does not exist in the Registry, a form is sent back,
containing *at least* fields where the Poster certifies willingness to
abide by the rules of the group (to include, certainly, no asking of
FAQs, use of informative subject lines, and perhaps standard wordwrap
lines, no MIMEry, no embedded html, ???). The post from the
unregistered post sits in limbo until
(a) the form comes back, in which case the user is registered,
(b) the form mail bounces, in which case the proposed post is
deleted,
(c) some period of time (a week?) passes with no reply, in which
case the post is returned to sender, and deleted from the
posting queue.
If the poster is registered, his address is $poster. savetc.pl would
do something like
if($clueless{$poster}){&RETURNTOSENDER($id)}else{&POST($id)}
The human moderator has the power, perhaps subject to appeal, to
sanction a poster for violating the rules, perhaps setting
$clueless{$poster}=1 for one month for the first offense, two months for
the second, and so on. I would reserve the assignment of a clueless
rating for things that cannot be autochecked (like post format, no
MIME/HTML), and put longer clueless ratings for things that require
reading the post (in particular, failure to RTFM, non-Perl CGI questions)
than for informationless subject lines.
(2) Antispam Machine.
I know nothing about these. My antispam machine consists of a sharp
perusal of my inbox and a fast application of my right middle finger.
No, not up. Down, on the k key. But the Perly Kings seem able to do
this, or so I've read on Usenet, which is Truth, right?
(3) Handling replies and followups.
This is the guts. Let perlyking.org be a host, with posts sent to
news@perlyking.org. savetc.pl writes a header for the approved
posting, something like
print HEADER "From: $id\@perlyking.com\n";
and somewhere else updates the tied hashes,
$poster{$id} = $user;
$subject{$id} =$subject;
where $subject is the post's subject line.
Followups are handled like any other post. For replies, savetc.pl goes
through the same user-checking routine, then picks off the $to and the
$subject fields from the mail header, and then does something like:
if ($subject eq $subject{$to}){&SENDON($poster{$to},$reply)}
with perhaps a more competetent test to catch Re: in the subject line.
I suspect that Perly Kings could improve on this substantially in order
to match posts with posters.
In retrospect, antispam filtering would not be necessary: *all* spam
would be caught by the registered-user check.
(4) Anticluelessness Autoresponder.
All posts and replies running through savetc.pl would be checked for
minimum format, e.g. line-length and absence of MIME/HTML garbage. If
such was found, it bounces with an explanation, written by Tom *after*
he returns from a well-deserved vacation in the mountains. One *might*
make a first cut at the subject line by requiring *some* standard indicator
of the content (I dunno: qw(Reviews Codecritique Training Ports Objects
Lore Databases))...such schemes often work poorly but at least they make
one think a little before posting.
I am not addressing moderation rules. One approach is to simply impose
sanctions ex-post, with the moderator passing judgement following
complaints from the (registered) users. So one just lets the thing run
and intervenes as necessary, and relies upon self-policing behavior by
posters who don't want to be dumped into the clueless box. I suspect
that public posting of the contents of the clueless box, reminiscent of
the stocks of Puritan Massachussetts, would be unnecessary. Says I,
fearing that I too might be such a laughing stock at some point.
---------------------------------------------------------------------------
Jason Christian University of California, Davis
jason@primal.ucdavis.edu Agricultural and Resource Economics
Office:(530)752-1357 FAX:(530)752-5614 Davis, CA 95616
------------------------------
Date: Fri, 13 Feb 1998 20:02:00 +0100
From: Luc Van Linden <Luc.VanLinden@esat.kuleuven.ac.be>
To: sme@planetpod.com
Subject: Re: ENCTYPE="multipart/form-data" QUESTION?!?
Message-Id: <34E498A8.51A21E3D@esat.kuleuven.ac.be>
Stewart Eastham wrote:
> I working on a script that allows the user to upload files to a server
> through a web browser. I have all of the PERL script up and working,
> but as soon as I add the ENCTYPE="multipart/form-data" text in the
> FORM tag in the HTML, I always get a "malformed header" error. My
> thinking is that I need to add a line to my .htaccess file for this
> directory, so that it recognizes "multipart/form-data". But I have no
> idea what this tag may be.
>
> Any help would be appreciated. Thanks a lot.
>
> stewart eastham
> sme@planetpod.com
Hey,
I once had a similar problem. My problem was solved when the
multipart/form-data was added to the "mime-types" by our web-administrator.
(I had to beg him to do that).
Groeten,
Luc.
------------------------------------
Luc Van Linden - Kandidatuurcentrum
Celestijnenlaan 200A - 3001 Heverlee
Tel. 016/32.70.74 - Fax 016/32.79.97
------------------------------------
------------------------------
Date: 13 Feb 1998 19:31:17 GMT
From: Eli the Bearded <*@qz.to>
Subject: Re: FAQless Forays (was: Code Example Needed)
Message-Id: <qz$9802131359@qz.little-neck.ny.us>
Tom Grydeland <Tom.Grydeland@phys.uit.no> wrote:
> ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au> wrote:
> > Indeed why don't we email a RTFM message to everybody the first time thay
> > post to this newsgroup?
> Indeed, I believe we do.
I know we do.
> Try modifying your From: address next time you post.
Yup, I did that a few months ago and noticed (and reported) a cosmetic
bug in the RTFM autoreplier. Then I changed twice more and I am happy
to say that the bug has been fixed.
It still doesn't help for those who munge their address though.
Elijah
------
the bug was causing the subject to appear in the body
------------------------------
Date: Fri, 13 Feb 1998 19:48:56 GMT
From: slocum@io.NOSPAM.com (Brett Slocum)
Subject: Re: Fork/Threads
Message-Id: <34e4a1d5.14331750@news.io.com>
I was just dealing with the same problem, except I was trying to fork
off search engine registrations. Any comments on my waitpid() code
would be appreciated. My perl snippet follows:
#!/usr/local/bin/perl
$| = 1; # set to flush after every line
print "Before forking...\n";
@bunch_of_websites = ('website 1', 'website 2', 'website 3');
@pid = ();
$id = 0;
foreach $website (@bunch_of_websites) {
if ($pid = fork) {
print "Parent after forking $website:$pid...\n";
$pid[$id++] = $pid;
} else {
print "Child after forking $website...\n";
exit(0);
}
}
# I put wait code in because my similar application accesses a
database
print "Parent start waiting...\n";
foreach $id (@pid) {
waitpid $id, 0;
}
print "Done waiting...\n";
exit(0);
Output: (notice that the parent actually does wait for the last child
to exit)
Before forking...
Parent after forking website 1:1750...
Child after forking website 1...
Child after forking website 2...
Parent after forking website 2:1751...
Parent after forking website 3:1752...
Parent start waiting...
Child after forking website 3...
Done waiting...
Brett Slocum, slocum AT io DOT com, unSPAM address to reply
http://www.io.com/~slocum/
Tekumel Home Page: www.io.com/~slocum/tekumel.html
GURPS Home Page: www.io.com/~slocum/gurps.html
------------------------------
Date: Fri, 13 Feb 1998 20:03:05 +0100
From: Luc Van Linden <Luc.VanLinden@esat.kuleuven.ac.be>
Subject: htpasswd
Message-Id: <34E498E9.D7CFA996@esat.kuleuven.ac.be>
Hello,
The command "htpasswd" doesn't seem to work in my "perl"-scripts.
The perl-script is written correctly and "htpasswd" works form the
command line in unix, so there must be another problem.
Is it possible that I need a "better" htpasswd ? If so, where can I
download it ?
Groeten,
Luc.
------------------------------------
Luc Van Linden - Kandidatuurcentrum
Celestijnenlaan 200A - 3001 Heverlee
Tel. 016/32.70.74 - Fax 016/32.79.97
------------------------------------
------------------------------
Date: 13 Feb 1998 19:28:44 GMT
From: spidaman@well.com (Ian Kallen)
Subject: Re: htpasswd
Message-Id: <6c26tc$o93$1@was.hooked.net>
Luc Van Linden (Luc.VanLinden@esat.kuleuven.ac.be) wrote:
: The perl-script is written correctly and "htpasswd" works form the
: command line in unix, so there must be another problem.
Is the path set up correctly? Perhaps showing relevant the code would help
folks help you.
--
Ian Kallen <spidaman@well.com>
"Like so many Americans, she was trying to construct a life that made
sense from things she found in gift shops."
-- Kurt Vonnegut, Jr.
------------------------------
Date: 13 Feb 1998 11:12:12 -0800
From: rone+usenet@ennui.org (boar dome)
Subject: Re: Killfile Triage
Message-Id: <6c25uc$cum$1@shell13.ba.best.com>
In article <34e1a3b3$1$fuzhry$mr2ice@news1.mnsinc.com>,
Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org> wrote:
>In <6bnv7o$n1g$1@csnews.cs.colorado.edu>, on 02/09/1998
> at 10:16 PM, Tom Christiansen <tchrist@mox.perl.com> said:
>>The last directive in the following group
>>destroys any postings related to spam in any fashion. In particular,
>>this is to get rid of postings by people who like to put quirky "nospam"
>>gimmicks in their addresses, making it difficult to contact these people.
>>Let them eat /dev/null! Such "From" lines are not just a pain in the
>>butt; they are also not legal, and I zap illegal messages.
>Sigh! Good advice costs nothing and it's worth the price. The presence of
>"nospam" in an address does not mean that it is munged, that it is illegal
>or even that it is undeliverable. Anyone with half a clue would recognize
>that this filter will hit valid addresses as well as the invalid ones.
If you use a valid email address that looks like an invalid email
address, it's your own fault if people choose to ignore it.
rone
--
Chaining yourself to a stump isn't civil disobedience unless you're really
against stump-chaining laws.
- gomi no sensei <gomi@best.com>
------------------------------
Date: Fri, 13 Feb 1998 11:40:17 -0800
From: "P. Schmitz" <schmitzp@no.spam.wxs.nl>
Subject: Re: Location: returns empty document?
Message-Id: <34E4A1A1.75102E97@no.spam.wxs.nl>
Martien Verbruggen wrote:
> > Does anyone have any idea why the following perl script:
> >
> > print "Location: www.yahoo.com\n\n";
> >
> > doesn't redirect my browser to Yahoo!, but instead gives a 'Document
>
> This is not a perl problem. Perl will neatly compile and run that
> line. It is either a problem with your server, your browser, or with
> the implementation of the HTTP protocol. All of those are discussed in
> the comp.infosystems.www.* groups. You'd be better off asking there.
Nope. The same thing in a C++ cgi-bin works fine, so the server, browser and
HTTP are not the problem. By the way, the actual test I used had
http://www.yahoo.com, so that's not it either.
> > The same thing in a C++ CGI-bin works
>
> Then maybe the perl script never gets executed by your server. It's
> still the same thing. That would be a problem with your server setup.
It does get executed. The weird thing is that this works fine:
print "Content-type: text/html\n\nTest";
It prints the word Test in my browser. So, that's not it either...
I know this might not be a perl related problem at all, but it _could_ be,
that's why I'm asking about it here.
Pepijn
------------------------------
Date: Fri, 13 Feb 1998 11:35:26 -0800
From: "P. Schmitz" <schmitzp@no.spam.wxs.nl>
Subject: Re: Location: returns empty document?
Message-Id: <34E4A07E.663AE4D1@no.spam.wxs.nl>
Hi Holly,
Holly Sommer wrote:
> P. Schmitz wrote:
>
> : print "Location: www.yahoo.com\n\n";
>
> Because you need to give the location as a complete URL, with the
> http:// and all.
Sorry about that. The actual test I used did have a complete URL, but I
typed it into the message instead of copy-and-pasting it. This time I did
copy and paste:
print "Location: http://www.yahoo.com\n\n";
It's exactly the same as in the C++ source, yet this gives a 'Document
contains no data' error and the C++ version redirects the browser to Yahoo!,
as it should. So it still could be a perl-related problem...
Pepijn
------------------------------
Date: 13 Feb 1998 18:56:29 -0000
From: chrisb@jesmond.demon.co.uk (Chris Benson)
Subject: Re: on reading FAQs and gurus answering questions
Message-Id: <6c250t$8mm@jesmond.demon.co.uk>
In article <34E370A5.7E0DC901@silcom.com>,
Nathan Young <nathan@ncyoung.com> wrote:
>There are two complexities I'd like to add here.
Mind if I add one more? :-)
[useful comment deleted].
Something else that has changed the clp(m?) world is CPAN. Now a lot of
the useful work previously published in the newsgroup is done there --
it makes a lot of hard work less visible to the NG and removes some of
the high level comment + discussion (to mail or lists) that new code caused.
It was interesting (and very welcome) to see TomC's essays and useful
programs the last few days -- perhaps a welcome attempt to recreate
something of the atmosphere of mutual help and sharing and intelligent
debate of the days of yore.
--
Chris Benson
------------------------------
Date: Fri, 13 Feb 1998 14:41:30 -0500
From: "Reza E. Jahromi" <reza@avestec.com>
Subject: Perl 5.003 and IIS on NT 4.0
Message-Id: <34E4A1EA.26A2E360@avestec.com>
I am using win32 perl with IIS on NT 4.0 and having the following
problem:
#!perl
print "Content-type:text/html\n\n";
print "<html>\n";
print "<body>\n";
$_ = `time < dummy.dat`;
if (m/([0-9]*):([0-9]*):([0-9]*)/) {
$datetime .= " $1:$2:$3";
print "$datetime\n";
}
$line = `select * from my_table`;
print $line;
$test= exec ("isql -U$user -P$pswd -S$server_name -Q \"$line\""); #
This line fails from IE, $test is null
print "<P>";
print $test;
print "</body>";
print "</html>";
The above script works flawlessly from the NT Command Prompt. However
it fails to process the backticked () line which contains the ISQL
executable when run within a browser. At first I thought this was an
ISQL problem, but I replaced ISQL with another executable and got the
same results. I am assuming that this is somehow related to some
environment settings for IIS, NT, or PERL.
Has anyone experienced this before? And if so, would you please share
with us how you fixed it?
Your help is greatly appreciated.
Reza Jahromi
Avestec Consulting, Inc.
------------------------------
Date: Fri, 13 Feb 1998 19:02:56 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Question concerning backreferences
Message-Id: <EoBzKw.BGy@world.std.com>
hallm4@cortez.sss.rpi.edu (StarScream) writes:
>I was writing a small program today, and I was doing a bit
>of regexp'ing. Rather than deal with defining another
>variable, I decided to try to modify $1 directly, since it
>was holding the data I was looking for. Perl dies out,
>complaining about trying to modify a read-only variable.
>"Read Only?" I say, and open my camel book. Yup, sure enough,
>under its definition, they are read only. Browsing through
>the FAQ, I didn't notice anything concerning this topic, so
>I decided to risk the killfile and ask this question: Why?
One guess would be that then $1 may not mean what its documented to
mean. (It becomes either what it is documented to mean or whatever the
programmer decides it means.)
Variables are cheap. If it comes to a choice between creating
maintainable code and saving a variable, splurge on the variable.
Most of the time, I forgo using $1, etc entirely and use the list
context return of the match operator save the data in a variable that
would make sense when reading the code.
($size,$name) = /(\d+)\s+(.*)/
--
Andrew Langmead
------------------------------
Date: Fri, 13 Feb 1998 12:34:21 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: Question concerning backreferences
Message-Id: <34E49FD5.165CE809@5sigma.com>
Well, you can always just say
s/(foo)/bar/;
which is very similar to the (non-functional)
/(foo)/;
$1 = "bar";
As to why it's this way, hmm, I don't know. Personally I've
wished for:
/(foo) (bar)/ = ("xyzzy", "plugh")
before, and it shouldn't be *that* hard to do, but (1)
regexp changes are very difficult to implement because of
performance and regression constraints, and (2) convenience
changes like this are much lower on the priority scale than
bug fixes and major new functionality (like threads).
-joseph
StarScream wrote:
>
> I was writing a small program today, and I was doing a bit
> of regexp'ing. Rather than deal with defining another
> variable, I decided to try to modify $1 directly, since it
> was holding the data I was looking for. Perl dies out,
> complaining about trying to modify a read-only variable.
>
> "Read Only?" I say, and open my camel book. Yup, sure enough,
> under its definition, they are read only. Browsing through
> the FAQ, I didn't notice anything concerning this topic, so
> I decided to risk the killfile and ask this question: Why?
>
> Probably for a good reason, but since I'm in a curious mood,
> could someone give a -v answer?
--
Joseph N. Hall, prop., 5 Sigma Productions mailto:joseph@5sigma.com
Author, Effective Perl Programming . . . . . http://www.effectiveperl.com
Perl Training . . . . . . . . . . . . . . . http://www.perltraining.com
------------------------------
Date: Fri, 13 Feb 1998 14:00:44 -0500
From: Boris 'pi' Piwinger <3.14@Math.MIT.edu>
Subject: Re: Quickie: regexp for valid e-mail addresses
Message-Id: <34e496e6.0@news.netway.com>
Dennis Whitney <dennis@ironlight.com> wrote:
>the first expression checks for valid formating and the 7 TLDs (+ int),
There are many more TLDs!
pi
--=20
Yogi Berra said:
>It's like deja vu all over again!
------------------------------
Date: 13 Feb 1998 18:08:58 GMT
From: alansz@araw.mede.uic.edu (Alan Schwartz)
Subject: Re: regexp: /^[800|888]/ vs. /^8[0{2}|8{2}]/
Message-Id: <6c227q$4d4c$1@piglet.cc.uic.edu>
Fritz Knack <fritz.knack@POPULUS.net> writes:
>For a report I've written, I'm trying to determine if a given phone
>number is an 800-class number, i.e., it begins with 800 or 888.
>
>Anyway, below are two snippets of code. The first one is what works
>the way I want it to. The second pulls too much, e.g., area code 813
>(Houston? Dallas?) "counts" as an 800-class number.
>
>Can anyone tell me what's going on? I would have though the two were
>classic TMTOWTDI. (If it matters: perl 5.0003_07, Win32 build 311.)
>
># Snippet 1:
> if ($phone =~ /^8[0{2}|8{2}]/) {
># do stuff
> }
>
># Snippet 2:
> if ($phone =~ /^[800|888]/) {
># do stuff
> }
The []'s enclose a character class. Your second snippet says
"anything that begins with one of these characters:
8, 0, 0, |, 8, 8, or 8."
Your first snippet says "begins with 8, followed by one of these
characters: 0, {, 2, }, |, 8, {, 2, or }." So it should pick up
area codes like 82x, 80x, and 88x, as well.
What I think you meant was: (800|888), which means either 800 or 888.
I got curious, reading this, about whether there was a difference
in performance between (800|888), 8(00|88), and 8[08]{2}, along with
versions using (?: instead of (.
Here's an informal test program:
#!/usr/local/bin/perl
$pat = $ARGV[0];
# Do this 1000 times:
foreach $run (1..1000) {
@nums = @matching = ();
# Generate 1000 random 3-digit numbers (100-999)
foreach (1..1000) {
push(@nums,int(rand() * 900 + 100));
}
# do a pattern match on each
@matching = grep(m/$pat/o,@nums);
}
The test system was a Sparcstation 2, SunOS 4.1.3_U1, perl -v reports:
This is perl, version 5.004_04 built for sun4-sunos
(with 1 registered patch, see perl -V for more detail)
(That patch being REFCASE1)
Here were the results:
user process time system time
'^8(?:00|88)' 148.7 0.7
'^8(00|88)' 148.7 0.9
'^(800|888)' 170.3 0.4
'^(?:800|888)' 173.6 0.4
'^8[08]{2}' 146.9 0.3
As might be expected, patterns which require an '8' at the front
explicitly are quickest -- that can be checked without dealing
with the alternation or character classes. Interesting to me was:
(1) The interpreter didn't require more time when using ( than (?:.
Perhaps it interprets them to the same thing if it notices that
you never use $1?
(2) ^8[08]{2} is slightly faster than ^8(?:00|88). I think one of the
ORA Perl books (camel?) mentions that alternation is relatively
slow, but both seemed to do pretty well here. This is probably a
tribute to the pattern-match compiler, which may again have compiled
them to very similar patterns.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Alan Schwartz | Disclaimer: I represent no one
<alansz@uic.edu> |
Asst. Prof. of Clinical Decision Making | Life is what happens to you while
University of Illinois at Chicago | you're busy making other plans
Department of Medical Education | - J. Lennon
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: Fri, 13 Feb 1998 14:31:30 -0500
From: joe.mcmahon@gsfc.nasa.gov (Joe McMahon)
Subject: Re: scope of $<digit>
Message-Id: <joe.mcmahon-1302981431300001@prtims.stx.com>
In article <34E2EC56.2656@mds.qmw.ac.uk>, David Proffitt
<D.M.Proffitt@mds.qmw.ac.uk> wrote:
>This fragment checks lines of text for matching pairs of HTML style
>tags. If there is a matching pair it just prints out the line, if there
>is only an opening tag it adds a closing tag to the end of the line.
>
>The conditionals work OK but the closing tags are empty - there is never
>anything in $1
>
>The FAQs say that the scope of $<digit> is the current block or until
>the next match using a backreference
>
>I'm obviously missing something about the behaviour of $<digit> ?
>
>while (<IN>) {
> chomp;
> if (/<(.*?)>/ and /<\/$1>/) {
> print "debug1 = $1";
> print OUT "$_\n";
> }
> elsif (/<(.*?)>/ and /[^<\/$1>]/) {
> print "debug2 = $1";
> print OUT "$_<\/$1>\n";
> }
>}
I seem to see two distinct pattern matches here. The first one does set
$1, but the the second one comes along and doesn't set any of the $n variables;
I (based on instinct) would expect the $n variables to be clobbered. I'd
recommend two-staging it:
while(<IN>) {
my ($tag,$rest);
chomp;
print; # Echo the line
if ($tag = /<(.*?)>/) { # We have an open tag ...
print; # Echo line in both cases
print "</$tag>"
unless m{</$tag>}; # Close tag if required
}
print "\n"; # Add newline in any case
}
How's that? Sometimes changing flow-of-control is better than making
expressions or patterns more complex.
--- Joe M.
--
--- Joe M.
------------------------------
Date: 13 Feb 1998 19:23:23 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: So what about last summer's RFD? Let's go moderated.
Message-Id: <6c26jb$pne$1@news.orst.edu>
In article <34E3F2BF.3FF07085@hotmail.com>,
Larry D'Anna <ldanna@hotmail.com> wrote:
>John Stanley wrote:
>> If this same proposal comes up again, I will be just as opposed to any
>> mandate for spammable addresses as I was when it came up the first
>> time. There is no reason this group needs to serve up verified
>> addresses to spammers on a silver platter.
>
>This seems to be a silly reason not to have a moderated group.
I didn't say we shouldn't have a moderated group. I said we should not
mandate verified deliverable addresses so spammers can harvest with zero
effort.
>> If it was going to die because there isn't a moderated group, it would
>> have died a long time ago.
>
>It is dying, slowly.
If it was dying, it would have been dead a long time ago. Otherwise, it
is dying too slowly to fit the definition of "dying".
------------------------------
Date: 13 Feb 1998 14:36:05 -0500
From: James Hebert <hebert@cs.fsu.edu>
Subject: Re: Tell me your programming highs!
Message-Id: <oglk9azb8m2.fsf@cs1.cs.fsu.edu>
He wanted *working* code. =P
(To the humor impared: go away.)
jim
Myles Barrett Williams <a@b.c.d> writes:
> johnnyzine@hotmail.com writes:
> > It's a specialty theme for computer programmers: I want to hear your
> > experiences of programming under the influence. Have you done this?
> > Regularly? Any stories? (No fiction.) Illustrations, photos and working
> > code (functions, programs, etc) welcome.
>
> It's my understanding that the BSD sockets API was designed during
> such an episode.
>
> --
> mwilliam@ | "When you see me again, it won't be me."
> cs.utk.edu | I successfully filter out ALL junk E-mail.
------------------------------
Date: Fri, 13 Feb 1998 08:46:52 -0600
From: Graham Barr <gbarr@ti.com>
Subject: Re: The Young Man and the Beach
Message-Id: <34E45CDC.D6B5D299@ti.com>
Mark Kramer wrote:
<ungrateful gibberish deleted>
It is posts like these that are likely to alienate the people on
this list who soul purpose for being here is to help. Sure
we might get a little short with people at times but believe
me this newsgroup would be almost useless if all these
"good samaritans" left to help others who appreciated their
input.
--
Originality is the ability to conceal your source.
------------------------------
Date: 13 Feb 1998 19:15:35 GMT
From: billy@cast.msstate.edu (Billy Chambless)
Subject: Re: Tom wins flamer of the year award!
Message-Id: <6c264n$dc2$1@nntp.msstate.edu>
In article <6btb88$2c4$4@csnews.cs.colorado.edu>, Tom Christiansen <tchrist@mox.perl.com> writes:
|> [courtesy cc of this posting sent to cited author via email]
|>
|> In comp.lang.perl.misc, Douglas Clifton <doug@weboneinc.com>
|> writes a smiley face. I'm trying to figure out just what business
|> "We Bone, Inc." might be in. :-)
Or is it, "Wee Bone, Inc." ?
--
* "And there _is_ a real world. In fact, some of you
* are in it right now." -- Gene Spafford
------------------------------
Date: Fri, 13 Feb 1998 12:35:05 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: Variable interpolation or reference?
Message-Id: <34E4A002.3CFED465@5sigma.com>
It's a symbolic (or "soft") reference. Man perlref.
-joseph
Mark666769 wrote:
>
> I see that ${$var} creates a new variable $test,
> but I'm not quite sure why. In other words,
> what concept is coming into play here? Is this
> another form of variable interpolation? Or is this
> creating a reference with $$ ? Or something else?
--
Joseph N. Hall, prop., 5 Sigma Productions mailto:joseph@5sigma.com
Author, Effective Perl Programming . . . . . http://www.effectiveperl.com
Perl Training . . . . . . . . . . . . . . . http://www.perltraining.com
------------------------------
Date: 13 Feb 1998 14:32:03 -0500
From: kcohen@julius.ling.ohio-state.edu (Kevin B Cohen)
Subject: what does "deprecate" mean?
Message-Id: <6c273j$sd8@julius.ling.ohio-state.edu>
okay, i *know* what it means to "deprecate" in english, but what does
it mean in perlish? here are some examples of usage (hope i'm not
violating any laws of copyright...):
"This usage is vaguely deprecated, and may be removed in some future
version of Perl." (camel, 2nd ed., pg. 72)
"Use of $* is now deprecated, and is allowed only for maintaining
backwards compatibility with older versions of Perl." (camel, 2nd
ed., pg. 129)
I can imagine deprecating a novel or a usage in English, but I'm
having trouble imagining deprecating a variable....
kevin
------------------------------
Date: 13 Feb 1998 14:42:23 -0500
From: Douglas McNaught <doug@tc.net>
Subject: Re: what does "deprecate" mean?
Message-Id: <m23ehnb8bk.fsf@ono.tc.net>
kcohen@julius.ling.ohio-state.edu (Kevin B Cohen) writes:
> okay, i *know* what it means to "deprecate" in english, but what does
> it mean in perlish? here are some examples of usage (hope i'm not
> violating any laws of copyright...):
I think this falls under "fair use", so you're OK.
> I can imagine deprecating a novel or a usage in English, but I'm
> having trouble imagining deprecating a variable....
What it really means is "the use of this {feature,variable} is
deprecated", either because it may go away in the future or because
it's has deleterious consequences.
>From the Jargon File:
deprecated /adj./
Said of a program or feature that is considered obsolescent and in the
process of being phased out, usually in favor of a specified
replacement. Deprecated features can, unfortunately, linger on for
many years. This term appears with distressing frequency in standards
documents when the committees writing the documents realize that large
amounts of extant (and presumably happily working) code depend on the
feature(s) that have passed out of favor. See also {dusty deck}.
-Doug
--
sub g{my$i=index$t,$_[0];($i%5,int$i/5)}sub h{substr$t,5*$_[1]+$_[0],1}sub n{(
$_[0]+4)%5}$t='encryptabdfghjklmoqsuvwxz';$c='fxmdwbcmagnyubnyquohyhny';while(
$c=~s/(.)(.)//){($w,$x)=g$1;($y,$z)=g$2;$w==$y&&($p.=h($w,n$x).h($y,n$z))or$x==
$z&&($p.=h(n$w,$x).h(n$y,$z))or($p.=h($y,$x).h($w,$z))}$p=~y/x/ /;print$p,"\n";
------------------------------
Date: Fri, 13 Feb 1998 17:30:40 +0000
From: Dr John Stockton <jrs@merlyn.demon.co.uk>
Subject: Re: Year 2000 Compliance: Lawyers, Liars, and Perl
Message-Id: <9i+tuhAANI50EwEk@merlyn.demon.co.uk>
JRS: In article <47KE.106$b%5.175245@ptah.visi.com> of Thu, 12 Feb 1998
21:48:48 in comp.software.year-2000, Peter Seebach <seebs@plethora.net>
wrote:
>I dread the 34,667 bug.
Which is ?
--
John Stockton, Surrey, UK. jrs@merlyn.demon.co.uk Turnpike v1.12 MIME.
Don't Mail News. Y2k for beginners http://www.merlyn.demon.co.uk/year2000.txt
My list of Critical Dates is now at http://www.merlyn.demon.co.uk/critdate.htm
Web <URL: http://www.merlyn.demon.co.uk/> --- includes FAQqish topics & links.
------------------------------
Date: Fri, 13 Feb 1998 19:04:52 GMT
From: seebs@plethora.net (Peter Seebach)
Subject: Re: Year 2000 Compliance: Lawyers, Liars, and Perl
Message-Id: <oP0F.69$TW1.327533@ptah.visi.com>
In article <9i+tuhAANI50EwEk@merlyn.demon.co.uk>,
Dr John Stockton <jrs@merlyn.demon.co.uk> wrote:
>JRS: In article <47KE.106$b%5.175245@ptah.visi.com> of Thu, 12 Feb 1998
>21:48:48 in comp.software.year-2000, Peter Seebach <seebs@plethora.net>
>wrote:
>>I dread the 34,667 bug.
>Which is ?
On a system with 16-bit ints, struct tm's tm_year, years since 1900, will
top out around 32,767. Thus, 34,667 is the last year such systems can hold.
(I should have said 34,668 bug.)
-s
--
seebs@plethora.net -- I am not speaking for my employer. Copyright '97
All rights reserved. Boycott Spamazon! End Spam. C and Unix wizard -
send mail for help, or send money for a consultation. Visit my new ISP
<URL:http://www.plethora.net/> --- More Net, Less Spam! Plethora . Net
------------------------------
Date: 13 Feb 1998 18:55:52 GMT
From: Eli the Bearded <*@qz.to>
Subject: Re: Zero-width positive lookahead assertion Q
Message-Id: <qz$9802131331@qz.little-neck.ny.us>
Sitaram Chamarty <sitaram@diac.com> wrote:
> On Thu, 12 Feb 1998 16:26:36 GMT, David Griffin <griffin@i33.com> wrote:
> >$num =~ s/(\d{1,3})(\d{3})(?=\d{3})*$/\1,\2/g;
> I'm not really sure the "*" (match >= 0 times) quantifier is
> applicable to lookahead assertions...that's prolly your trouble.
That is a good point, but his RE doesn't work even if he puts the
* inside the assertion.
:r!echo 1238689123723457 | perl -wpe 's/(\d{1,3})(\d{3})(?=(\d{3})*$)/$1,$2/g'
1,238689,123723,457
David and I corresponded over this via email, resulting in my actually
benchmarking a few methods. 'mine' is the one I put as a sig line in
my post. 'faq1' is the first one offered in the FAQ. 'faq2' is Andrew
Johnson's version in the FAQ. And 'david' is the final one David sent
me.
:r! perl comma.bnch
Benchmark: timing 2000 iterations of faq1, faq2, mine, yours...
faq1: 14 secs (14.04 usr 0.00 sys = 14.04 cpu)
faq2: 6 secs ( 5.72 usr 0.00 sys = 5.72 cpu)
mine: 7 secs ( 7.34 usr 0.00 sys = 7.34 cpu)
david: 19 secs (20.19 usr 0.00 sys = 20.19 cpu)
This was perl 5.004_04 on a lightly loaded sparc 5.
:r! cat comma.bnch
#!/usr/bin/perl -w
use Benchmark;
timethese(2000, {
'mine' => sub { my $num = '1234567890' x 10;
($h,$t) = $num =~ /(\d{1,3})((?:\d{3})*)\b/;
@a = $t =~ /(...)/g;
unshift @a,$h;
$num = join ",",@a;
},
'faq1' => sub { my $num = '1234567890' x 10;
1 while $num =~ s/^(-?\d+)(\d{3})/$1,$2/;
},
'faq2' => sub { my $num = '1234567890' x 10;
$num = reverse $num;
$num =~ s<(\d\d\d)(?=\d)(?!\d*\.)><$1,>g;
$num = reverse $num;
},
'david' => sub { my $num = '1234567890' x 10;
$num =~ s/(\d{1,3})(?=(?:\d\d\d)+(?!\d))/$1,/g
}
});
__END__
These are not all quite interchangable, but the differences in speed
are telling: repeated s/// comes out slow, as expected, but also so
does heavy use of look ahead assertions.
Elijah
------
whose code faired better than he thought it would
------------------------------
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 1891
**************************************