[10815] in Perl-Users-Digest
Perl-Users Digest, Issue: 4416 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Dec 13 23:07:21 1998
Date: Sun, 13 Dec 98 20:00:15 -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 Sun, 13 Dec 1998 Volume: 8 Number: 4416
Today's topics:
Re: ($e_mail !~ /\w+[-\w]*\@\w+[-\w]*\.\w+/) (Emmett McLean)
Re: ($e_mail !~ /\w+[-\w]*\@\w+[-\w]*\.\w+/) <merlyn@stonehenge.com>
Re: a simple puzzle (I suspect) <uri@sysarch.com>
Acceptable Filehandles <support@counter.w-dt.com>
Re: CGI.pm vs. old way I'm used to? (Emmett McLean)
Re: Flock (Tad McClellan)
Re: getting http-referer <merlyn@stonehenge.com>
Re: getting http-referer (Larry Rosler)
Re: getting http-referer <merlyn@stonehenge.com>
Re: PC to Unix Problem (Emmett McLean)
Perl and FTP - without modules <minich@globalnet.co.uk>
Re: Random integer numbers (1,2,3,4,5....,.....) HOW??? <tobix@irctos.org>
scirpt problem <tyrnt@hempseed.com>
Re: scirpt problem (Martien Verbruggen)
Re: Sorting problem: Is there a better way? <uri@sysarch.com>
Re: Sorting problem: Is there a better way? (Larry Rosler)
Re: Sorting problem: Is there a better way? (Allan M. Due)
Re: Use Perl from C (Emmett McLean)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 13 Dec 1998 16:41:20 -0800
From: emclean@slip.net (Emmett McLean)
Subject: Re: ($e_mail !~ /\w+[-\w]*\@\w+[-\w]*\.\w+/)
Message-Id: <751mrg$7cg@slip.net>
Randal wrote :
>Yes. Don't use this code. Go immediately to the Perl FAQ where
>it asks and answers "How do I check a valid email address?".
>The first paragraph after this is "You can't."
>
>Please stop swimming upstream... you missed the spawning season. :)
Just a comment. Aside from the fact that no one has bothered
to post the FAQ in a long time.
It would be nice for the Perl community that comp.lang.perl.misc
be a forum for asking questions about Perl rather than a forum for
a few people who parade as Perl gurus who disparage new
users, grumble on literate posts, and then post small tid bits
of information. Simple questions allow users at all levels to
contribute, not just the people who've been programming Perl
their entire careers.
In my case I researched the question for over a half hour with
Wall's text and didn't come up with an answer. A half hour is about
as much as most people spend researching a question which has
a very simple answer.
So if you're an advanced user and you've seen the question in the FAQ
and you don't want to respond, don't. Just skip it. Leave the
question for other, perhaps new, newsgroup participants.
While I appreciate the help offered in answers to my questions
I think some of the people in this group should lighten up. Either
that or some day we'll be programming in Visual Basic.
My two cents.
Again, thanks for the help.
Cheers,
Emmett
------------------------------
Date: Mon, 14 Dec 1998 02:02:52 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: ($e_mail !~ /\w+[-\w]*\@\w+[-\w]*\.\w+/)
Message-Id: <8cd85nqy4n.fsf@gadget.cscaper.com>
>>>>> "Emmett" == Emmett McLean <emclean@slip.net> writes:
Emmett> Randal wrote :
>> Yes. Don't use this code. Go immediately to the Perl FAQ where
>> it asks and answers "How do I check a valid email address?".
>> The first paragraph after this is "You can't."
>>
>> Please stop swimming upstream... you missed the spawning season. :)
Emmett> Just a comment. Aside from the fact that no one has bothered
Emmett> to post the FAQ in a long time.
The FAQ doesn't get posted because it is INCLUDED with your copy of
Perl. And a mini-FAQ gets posted here every few days that says that.
And a copy of *that* gets sent to you after your first post to this
group (remember that mail you got?). And another mini-FAQ gets posted
every few days to comp.lang.perl.announce as well. Do we need to
attach this info to EVERY post? <sigh>
Emmett> It would be nice for the Perl community that comp.lang.perl.misc
Emmett> be a forum for asking questions about Perl rather than a forum for
Emmett> a few people who parade as Perl gurus who disparage new
Emmett> users,
In what way did "read the FAQ" disparage you? It was accurate and to
the point. Yes, I attached an exasparated comment to the end because
I've seen this mis-question and mis-answer all too often here. But as
you can see above, at least I put a smiley face on it.
Emmett> grumble on literate posts, and then post small tid bits
Emmett> of information. Simple questions allow users at all levels to
Emmett> contribute, not just the people who've been programming Perl
Emmett> their entire careers.
I encourage new users, but I also expect new users to QUICKLY
understand that there are FAQs and Dejanews available for first-line
research before posting worn-out questions word-for-word and wasting
*all* our time with it.
Emmett> In my case I researched the question for over a half hour with
Emmett> Wall's text and didn't come up with an answer.
Yes, I am intimately familiar with that text, and I can assure you
that the answer is not there. :)
Emmett> A half hour is about
Emmett> as much as most people spend researching a question which has
Emmett> a very simple answer.
Precisely. But five minutes with Dejanews would have found your
answer in six minutes. So why did you waste 24 other minutes?
Seriously.
Emmett> So if you're an advanced user and you've seen the question in the FAQ
Emmett> and you don't want to respond, don't. Just skip it. Leave the
Emmett> question for other, perhaps new, newsgroup participants.
No, I'm correcting a mis-answer also in this thread. I hate this FAQ
because it gets answered WRONG frequently as well. Mostly from other
well-meaning but underinformed posters.
Emmett> While I appreciate the help offered in answers to my questions
Emmett> I think some of the people in this group should lighten up. Either
Emmett> that or some day we'll be programming in Visual Basic.
In fact, I find these days that most of the time, I'm merely
correcting or augmenting the mis-1answers of others, and I still find
it necessary to do that about three to five times a day. If you'd
actually like me to go away, I can do that (maybe :), but then you'll
be left with not just NO information, but INCORRECT information. Do
you really want that? I don't think so.
--
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: 13 Dec 1998 19:57:28 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: a simple puzzle (I suspect)
Message-Id: <x7u2yzsfpj.fsf@sysarch.com>
>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
LR> [Posted to comp.lang.perl.misc and copy mailed.]
LR> In article <x71zm3ucxz.fsf@sysarch.com> on 13 Dec 1998 13:14:16 -0500,
LR> Uri Guttman <uri@sysarch.com> says...
LR> ...
>> s/(CELL\()("?)(.*?)(\2\))/$1$2\L$3\Q$4/g;
LR> ^
LR> s/(CELL\()("?)(.*?)(\2\))/$1$2\L$3\E$4/g;
this was after a late night and while watching football (pats lost :-().
some rotten part of my brain thought \E ended \L while another part
(stolen by larry) knew \Q did the job.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Sun, 13 Dec 1998 18:48:36 -0600
From: Mike <support@counter.w-dt.com>
Subject: Acceptable Filehandles
Message-Id: <36746062.B3DBA403@counter.w-dt.com>
How can I find out what characters you can use in file handles? Can you
use a vaiable as a file handle like
$info = "hi";
open ($info, "info.htm")
Would that be acceptable? What characters can't you use like #'s or
periods or what?
Thanks.
------------------------------
Date: 13 Dec 1998 17:02:15 -0800
From: emclean@slip.net (Emmett McLean)
Subject: Re: CGI.pm vs. old way I'm used to?
Message-Id: <751o2n$8p4@slip.net>
>In article <3671945C.D164FB9D@gusun.georgetown.edu>, Dave Stephens
>
>For one thing, something I love dearly, is that you can run your CGI
>from a command line for the debug stage. Running yoru code gives you
>this:
If you know what your environmental variables are you can
run your cgi's from the command line anyway by assigning
the environmental variables at the top of your script.
If that is the major feature it's not a big deal. The old way
appears much faster.
Cheers,
Emmett
------------------------------
Date: Sun, 13 Dec 1998 18:56:11 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Flock
Message-Id: <bnn157.482.ln@magna.metronet.com>
Mike (support@counter.w-dt.com) wrote:
: I looked at many docs,
You should look at the *most authoritative* docs *first*. Books
go out of date quickly, the standard docs are updated with
each new perl release.
The most authoritative docs are the *.pod files that are
included in the perl distribution.
They are already on your hard disk if you have a properly
installed perl.
: somepeople would say if you don't want to help,
somepeople? or you? I will not address your anonymous reference.
But I *did* help. I've been helping for a few years here.
I answered your question!
You want more than that, it would seem...
What _do_ you want? (rhetorical question, since I won't be
able to see your reply)
: without
: being snobbish,
It is not being snobbish.
It is being helpful.
Consulting the docs that you already have will increase
your productivity. You can get the answer must faster
that way, and it will also help with all *future* Perl
problems beside just your problem de jure if you know to
go check them first.
Increasing folk's productivity is a Good Thing.
: get the hell off the news group.
I do my best to resist killfiling individuals, but I'm gonna
have to plonk you now.
So long.
[ and I intend to keep on trying to increase people's productivity ]
: A news group is where people
: go for help.
A newsgroup is where people go for help after taking a stab at
getting the solution themselves.
It is not a place to get other people to do your work for you.
Tom Sawyer doesn't read this newsgroup. (heh, heh ;-)
: I looked up in many perl books,
See?
The standard docs are *better* than *any* book. Even the Camel.
Check them first, get the answer right away, and get back to
productive programming rather than post and wait hours or days
for the answer...
: just because it has flock
: (filehandle, 2);
But the standard docs that I quoted *do* say that you have
to provide a filehandle as the first argument.
The standard docs are better than your books.
: to me doesn't just come out and say it has to go after open.
It does *not* have to come after open().
But you do need to get a filehandle to supply when you call flock().
open() is just one way of getting a filehandle.
The standard docs can help you discover other ways to get
a filehandle too...
: Tad McClellan wrote:
: > Mike (support@counter.w-dt.com) wrote:
: >
: > : Why do you call flock after you open the file and not before?
: >
: > I think if you look up flock() in perlfunc it should be apparent:
: >
: > =item flock FILEHANDLE,OPERATION
: >
: > You must supply a filehandle as the first argument, so you
: > have to _get_ a filehandle first.
: >
: > You really need to look at the docs for 10-15 seconds before posting...
[ snip quoted .sig, a sign of lack of clue ]
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 14 Dec 1998 02:05:44 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: getting http-referer
Message-Id: <8c90gbqxzr.fsf@gadget.cscaper.com>
>>>>> "John" == John Bokma <postmaster@castleamber.com> writes:
John> AFAIK, locking is *not* needed when you *append*
John> to a file (single line), it's an atomic operation.
Only if you use sysopen and syswrite. Which you didn't.
print "Just another Perl hacker,"
--
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: Sun, 13 Dec 1998 19:02:51 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: getting http-referer
Message-Id: <MPG.10de1fb5da3df60c989958@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and copy mailed.]
In article <8c90gbqxzr.fsf@gadget.cscaper.com> on Mon, 14 Dec 1998
02:05:44 GMT, Randal Schwartz <merlyn@stonehenge.com> says...
> >>>>> "John" == John Bokma <postmaster@castleamber.com> writes:
>
> John> AFAIK, locking is *not* needed when you *append*
> John> to a file (single line), it's an atomic operation.
>
> Only if you use sysopen and syswrite. Which you didn't.
I think that using $|++ to force line-flushing for 'print' would work as
well, provided each line is small enough for a single write(2), which is
extremely likely.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 14 Dec 1998 03:22:21 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: getting http-referer
Message-Id: <8c1zm3qug1.fsf@gadget.cscaper.com>
>>>>> "Larry" == Larry Rosler <lr@hpl.hp.com> writes:
John> AFAIK, locking is *not* needed when you *append*
John> to a file (single line), it's an atomic operation.
>>
>> Only if you use sysopen and syswrite. Which you didn't.
Larry> I think that using $|++ to force line-flushing for 'print'
Larry> would work as well, provided each line is small enough for a
Larry> single write(2), which is extremely likely.
*unless* the small line (no matter how small) crosses a BUFSIZ (8K?)
boundary, in which case you'll most likely get two write(2)'s instead
of one. Bad news.
Again, either use flocking, or bypass STDIO, which is almost certainly
gonna ruin your day.
print "Just another Perl hacker,"
--
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: 13 Dec 1998 16:48:23 -0800
From: emclean@slip.net (Emmett McLean)
Subject: Re: PC to Unix Problem
Message-Id: <751n8n$7qs@slip.net>
Victor B Wagner <vitus@brass.fe.msk.ru> wrote:
>oleynikl@geocities.com wrote:
>: I've been learning Perl 5.0 for 2 days now. I'm trying to use Perl to solve a
>: problem. Whenever I create an ascii file in a PC environment and upload it to
>: a UNIX account, what I get is newline characters appearing everywhere. (ie: I
>: get ^M in vi and <cr> in nedit).
Install fgres from one of the comp.unix.sources archives. Then
you can change the ^Ms by typing
fgres "^M "" *.cgi
Emmett
------------------------------
Date: Sun, 13 Dec 1998 16:41:46 -0000
From: "Martin" <minich@globalnet.co.uk>
Subject: Perl and FTP - without modules
Message-Id: <750qo4$rbi$1@newnews.global.net.uk>
I was wondering if someone who knows a bit about FTP would be willing to
help me with a little problem I'm having. I've read RFC959 and understand
some of it and have a feeling that the bit I don't understand is where I'm
going wrong.
I get the following output:
220- HostName NAMEOFSERVER 1.65 Ready
220 Please enter your user name.
331 User name okay, Need password.
230 User logged in, proceed.
150 Ready to receive "/C/Foo/1.foo". Mode STREAM Type ASCII NO-PRINT.
426 Data connection error. Connection closed. Transfer aborted
221 Goodbye. Control connection closed.
I do get the file 1.foo being created but of size 0 bytes.
The code is:
use IO::Socket;
$host = 'foo.com';
$remote = IO::Socket::INET->new (Proto => "tcp",
PeerAddr => $host,
PeerPort => 21, );
unless ($remote) { die "cannot connect to http daemon on $host" }
$remote->autoflush(1);
&output;
print $remote "USER Userfoo\n";
&output;
print $remote "PASS Passwordbar\n";
&output;
print $remote "STOR 1.foo\n";
&output;
&output;
print $remote "QUIT\n";
&output;
close $remote;
exit;
sub output { while (<$remote>) { print; last unless /\d+-/ } }
Thanks
Martin
------------------------------
Date: 14 Dec 1998 04:11:42 +0100
From: Tobias Brox <tobix@irctos.org>
Subject: Re: Random integer numbers (1,2,3,4,5....,.....) HOW???
Message-Id: <xn6lnkb4du9.fsf@shark.td.org.uit.no>
Mark Stackhouse <stackhou@execpc.com> writes:
> for (1..15)
> {
> $number = int(rand 15)+1; #+1 eliminates 0 as a possible number
> print "$number\n";
> sleep 1; #not necessary :)
> }
As the rand (probably) is 31-bit, this is another aproach:
$number=(rand(1<<31)%15)+1;
--
TobiX In a world without fences, who needs gates?
http://www.td.org.uit.no/~tobias/
------------------------------
Date: Mon, 14 Dec 1998 01:16:24 GMT
From: "Tyrnt" <tyrnt@hempseed.com>
Subject: scirpt problem
Message-Id: <IFZc2.2811$f97.3013@news.rdc1.sdca.home.com>
Ok, i have been programming an awards script for a site and
it is comming along great. After 3 days of programming this script i have
came to a huge wall in my way because i dont know how to make what i want to
happen work. That is why i am posting this I was wondering if someone could
kindly help me out in my problem. Here is what i want to do:
Ok, I am using .dat files for flat file databases when a person
joins(registers) the info goes into a couple of dat files, i am going to
talk about the main one it goes into which is named list.dat. make the
program look through the .dat file ..match up the button name to a name of
the site on the .dat file then take the number at the end of the line in the
.dat file that matched up with the name of the button and then depending on
the amount of times the person has voted add 9 to it or 5 to it or 2 to the
number and then print that number to the same .dat file on the same line....
My problem is that i dont know how i would go about doing that.
and also with the same script i am getting this error:
Search pattern not terminated at
/usr/local/etc/httpd/sites/blizzardnexus.com/cgi-bin/award/award.cgi line
402.
and this is line 402:
($name,$email,$web,$website,$avghits,$start,$rank) = split (/\|\,$points);
can anyone see a problem with that?
Once i get this problem fixed i will want to know how i would go about make
a HTML validation where the scirpt goes to the page and makes sure that the
person put a certain code on their main page.
If anyone will help me out i would greatly appreciate it, This is my first
script so i am a little rusty and dont know how to do advanced stuff. I will
offer full credit on the script and in the readme file when it is released.
Thank you very much for taking the time to read this all the way through,
Thomas(AKA Tyrnt)
ICQ UIN:1802676
P.S. If you reply to this post could you please e-mail me also? thanx
------------------------------
Date: Mon, 14 Dec 1998 01:53:52 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: scirpt problem
Message-Id: <Qc_c2.82$SU4.213@nsw.nnrp.telstra.net>
In article <IFZc2.2811$f97.3013@news.rdc1.sdca.home.com>,
"Tyrnt" <tyrnt@hempseed.com> writes:
> Ok, i have been programming an awards script for a site and it is
> comming along great. After 3 days of programming this script i have
> came to a huge wall in my way because i dont know how to make what i
> want to happen work. That is why i am posting this I was wondering
> if someone could kindly help me out in my problem. Here is what i
> want to do:
Is this a CGI solution? If it is, I hope you are using the CGI,pm
module that comes with perl. It will save you many many hours of
reinventing the wheel.
> Ok, I am using .dat files for flat file databases when a person
> joins(registers) the info goes into a couple of dat files, i am
> going to talk about the main one it goes into which is named
> list.dat. make the program look through the .dat file ..match up the
> button name to a name of the site on the .dat file then take the
> number at the end of the line in the .dat file that matched up with
> the name of the button and then depending on the amount of times the
> person has voted add 9 to it or 5 to it or 2 to the number and then
> print that number to the same .dat file on the same line....
>
> My problem is that i dont know how i would go about doing that.
If it is a CGI, you will need to make sure that you lock the file when
you are updating it, to prevent multiple instances of your program to
try to do it at the same time.
It seems that the question you are asking is 'How do I change a line
in a flat text file?', right? The perl FAQ has an entry on this:
# perldoc perlfaq5
[snip]
How do I change one line in a file/delete a line in a
file/insert a line in the middle of a file/append to the
beginning of a file?
[snip]
In your case, you could read in your file, match the appropriate field,
output a line unchanged on no match, output the line changed on match.
> ($name,$email,$web,$website,$avghits,$start,$rank) = split (/\|\,$points);
The last backslash in the pattern needs to be a slash:
@stuff = split(/\|/, $points);
> Once i get this problem fixed i will want to know how i would go about make
> a HTML validation where the scirpt goes to the page and makes sure that the
> person put a certain code on their main page.
I am not sure what you mean. If you want to know wether the CGI
submission has a value for one of your variables, you can just check
for that.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | I think there is a world market for
Commercial Dynamics Pty. Ltd. | maybe five computers. --Thomas Watson,
NSW, Australia | chairman IBM, 1943
------------------------------
Date: 13 Dec 1998 20:07:31 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Sorting problem: Is there a better way?
Message-Id: <x7r9u3sf8s.fsf@sysarch.com>
without quoting a long piece on sorting, we seem to forget about the
orcian manouever. it has been shown to be faster than the ST in some
cases. stringifying would apply to it as well. in fact stringifying is
something we should promote as a sort booster (for some sets of data).
larry and john porter,
we should get off our collective duffs and create that sort article for
TPJ. just covering well these 3 issues (ST, OM ans stringifying) would be
plenty for 3+ pages. email me back offline to discuss the article. i
could outline a draft for us.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Sun, 13 Dec 1998 18:52:37 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Sorting problem: Is there a better way?
Message-Id: <MPG.10de1d51f12e3aab989957@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and copy mailed.]
In article <x7r9u3sf8s.fsf@sysarch.com> on 13 Dec 1998 20:07:31 -0500,
Uri Guttman <uri@sysarch.com> says...
>
> without quoting a long piece on sorting, we seem to forget about the
> orcian manouever. it has been shown to be faster than the ST in some
> cases. stringifying would apply to it as well. in fact stringifying is
> something we should promote as a sort booster (for some sets of data).
The following is the best I can do with Orcish, including speedups in
the 'sprintf' handling, which I also incorporated into the Default sort.
Orcish is indeed faster than ST, but not Default.
sub _Orcish{
# Orcish Maneuver with precomputation and stringifying.
my %h;
@h{ @$list1 } =
map { /(\D*)(\d*)/; sprintf '%s%9s', uc $1, $2 } @$list1;
my @sorted = sort { $h{$a} cmp $h{$b} } keys %h;
%h = ();
@h{ @$list2 } =
map { /(\D*)(\d*)/; sprintf '%s%9s', uc $1, $2 } @$list2;
@sorted = sort { $h{$a} cmp $h{$b} } keys %h;
}
Benchmark: timing 1000 iterations of Default sort, Orcish Maneuver,
Schwartzian Transform 2...
Default sort: 15 wallclock secs (14.45 usr + 0.00 sys = 14.45 CPU)
Orcish Maneuver: 21 wallclock secs (20.65 usr + 0.00 sys = 20.65 CPU)
Schwartzian Transform 2: 27 wallclock secs (26.92 usr + 0.00 sys =
26.92 CPU)
> larry and john porter,
>
> we should get off our collective duffs and create that sort article for
> TPJ. just covering well these 3 issues (ST, OM ans stringifying) would be
> plenty for 3+ pages. email me back offline to discuss the article. i
> could outline a draft for us.
I will email you the outline and draft I already started (on October
10!).
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 14 Dec 1998 03:03:05 GMT
From: Allan@Due.net (Allan M. Due)
Subject: Re: Sorting problem: Is there a better way?
Message-Id: <751v59$462$0@206.165.165.161>
[This followup was posted to comp.lang.perl.misc and a copy was sent to
the cited author.]
In article <MPG.10ddc70d34053191989955@nntp.hpl.hp.com>, Larry Rosler
(lr@hpl.hp.com) posted...
|[Posted to comp.lang.perl.misc and copy mailed.]
|
|In article <74ug54$s7l$0@206.165.167.208> on 12 Dec 1998 19:28:36 GMT,
|Allan M. Due <Allan@Due.net> says...
|> Well, the answer is obvious but I had never done this before and I thought
|> we had best let Larry rest up for X-mas ;-)
|
|Actually, Hanukkah, which starts this evening. But the preparation for
|that is minimal in any case. ;-)
|
|> ... As it is my first there are
|> likely holes in my design and corrective feedback is welcome. The letters
|> sub makes the leading characters random, while the numbers sub makes them
|> constant, but with the same number characters. I played with a common seed
|> value for each subroutine to keep the arrays constant across invocations of
|> the subs but it did not make any difference.
|
|The first significant change I made to your design was to return
|references to the test arrays, to minimize the overhead of copying.
|
|I retained your "best-in-class", and added another approach, which some
|of us (including John Porter and Uri Guttman) investigated here a few
|months ago. I started an article about it for The Perl Journal, but
|haven't had enough round tuits to finish it.
|
|The basic premise is that the callback to the comparison function, on
|each comparison, adds significant overhead -- compared to using the
|default alphanumeric sort, which is implemented internally simply as a
|direct call to the C function memcmp(). The overhead of creating
|strings that can be sorted by default and then extracting the original
|data is handled by the same map/sort/map paradigm as the Schwartz
|transform.
|
|Below are your original benchmarks for reference, followed by the
|modified code that I benchmarked and my results.
|
|> Benchmark: timing 1000 iterations of Schwartzian Transform 1, Schwartzian
|> Transform 2, designated order 1 , designated order 2 ...
|> Schwartzian Trans 1: 167 wallclock secs (167.25 usr + 0.00 sys = 167.25
|> CPU)
|> Schwartzian Trans 2: 137 wallclock secs (136.88 usr + 0.00 sys = 136.88
|> CPU)
|> designated order 1 : 356 wallclock secs (356.25 usr + 0.00 sys = 356.25
|> CPU)
|> designated order 2 : 352 wallclock secs (352.02 usr + 0.00 sys = 352.02
|> CPU)
[snip the cool new code]
|
|Benchmark: timing 1000 iterations of Default sort, Schwartzian Transform
|2...
|Default sort: 33 wallclock secs (33.34 usr + 0.00 sys = 33.34 CPU)
|Schwartzian Transform 2: 44 wallclock secs (43.66 usr + 0.00 sys =
|43.66 CPU)
|
|Comments on benchmarking:
|
|For the ST, I measured ~44 sec compared to your ~137 sec. As I doubt
|that our processors differ that greatly, I attribute the difference to
|the array-copying overhead that I got rid of.
I am afraid you seriously underestimate the antiquity of my system [P-
133, but I am getting a new computer from Santa ;-)]
When I run your new code vs. the way I did it originally I get:
Larry's version using refs:
Benchmark: timing 1000 iterations of Default sort, Schwartzian Transform
2...
Default sort: 101 wallclock secs (101.06 usr + 0.00 sys = 101.06 CPU)
Schwartzian Transform 2: 135 wallclock secs (134.73 usr + 0.00 sys =
134.73 CPU)
My way without refs:
Benchmark: timing 1000 iterations of Default sort, Schwartzian Transform
2...
Default sort: 102 wallclock secs (102.16 usr + 0.00 sys = 102.16 CPU)
Schwartzian Transform 2: 146 wallclock secs (145.83 usr + 0.00 sys =
145.83 CPU)
which indicates a difference, but not as dramatic a difference as one
might expect from the original post. Then again, I may be messing it up
in some way too <g>.
|When I further removed the calls to the initializers from the
|subroutines, and did them once only, the results became:
|
|Benchmark: timing 1000 iterations of Default sort, Schwartzian Transform
|2...
|Default sort: 17 wallclock secs (16.92 usr + 0.00 sys = 16.92 CPU)
|Schwartzian Transform 2: 26 wallclock secs (26.74 usr + 0.00 sys =
|26.74 CPU)
|
|The absolute difference of ~10 sec is now proportionately larger. When
|benchmarking, one should strive to minimize constant overhead.
Well, I never got this far but I am sure the results would be of similar
magnitude.
|General comment:
|
|A happy holiday season to everyone!
Happy Hanukkah!
AmD
------------------------------
Date: 13 Dec 1998 16:53:40 -0800
From: emclean@slip.net (Emmett McLean)
Subject: Re: Use Perl from C
Message-Id: <751nik$86p@slip.net>
Just my two cents :
>
>I try to use Perl from within Visual C++ 6.0 on Windows NT. However, all the
>examples I found (perlembed.htm, FAQ, ...) provide no sufficient
>information. I suggest that some LIBs are missing from the distribution
>(Activestate).
I'd recommend that you port the regexp library to VC++ and then program
in C and use the Perl as a pseudo markup langagage.
>
>Has anyone sufficiently created a project like the one mentioned above?
>Where can I find information on how to proceed?
Not me.
>
Emmett
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 4416
**************************************