[12007] in Perl-Users-Digest
Perl-Users Digest, Issue: 5607 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 8 21:07:27 1999
Date: Sat, 8 May 99 18:00:16 -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 Sat, 8 May 1999 Volume: 8 Number: 5607
Today's topics:
Re: CGI timeout in web-based listserv (Robert Watkins)
Re: CGI timeout in web-based listserv <design@raincloud-studios.com>
CGI.pm <jim@printcom.ie>
DOC: Using PerlSAX (a Perl binding for Simple API for X <ken@bitsko.slc.ut.us>
Fun with lists sstarre@my-dejanews.com
Re: Fun with lists <gellyfish@gellyfish.com>
Re: Fun with lists <rick.delaney@home.com>
Re: Fun with lists (Larry Rosler)
Re: Net::SMTP Problems. Help ! <gellyfish@gellyfish.com>
Re: Perl in the workplace sstarre@my-dejanews.com
Re: Rejecting unwanted hits <writer@wi.net>
Re: Rejecting unwanted hits <design@raincloud-studios.com>
Re: Sorting is too slow for finding top N keys... - UPD (Larry Rosler)
SRC: There be dragons <gellyfish@gellyfish.com>
Re: tcgrep not expanding command-line wildcards (Eric Pement)
Re: Telnet module and perl script to telnet to remote, (KaledBait)
trouble building perl on solaris <pcphil@cyberramp.net>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 08 May 1999 21:53:46 GMT
From: r-watkins@worldnet.att.net (Robert Watkins)
Subject: Re: CGI timeout in web-based listserv
Message-Id: <7h2bpv$qpl$1@bgtnsc02.worldnet.att.net>
In article <62%Y2.1092$vP2.316@news.rdc1.tn.home.com>, "Charles R. Thompson" <design@raincloud-studios.com> wrote:
>
>I would consider the end user's memory when taking this approach. I've
>crunched IE many a day sending too much data to the browser. Maybe I'm
>off (usually am) but I thought flushing the buffer at the top of a
>script would send print commands right out to the browser when doing
>something like this. I know I've seen incremental displays with less
>than 4kb of data.
>
After some testing I realize I must not know what you mean.
I set
$| = 1;
before the loop, then simply called
if ($count % 100 == 0) {
print "$count bulletins sent<BR>\n";
}
from within the loop instead of the nearly 4 Kb of garbage.
This still, however, does not send anything to the browser until the whole
thing is done, which is too long for a large number of e-mail addresses (and a
large message) as it times out after nearly 5 minutes. Am I doing it wrong?
Unless our lists get VERY long, I didn't think memory would be an issue. A
list of 1,000 names will send less than 50 Kb to the browser, and I sent out
(test conditions only) to a list of 15,000 names without a glitch in IE (5.0)
(perhaps because it is only doing so in small chunks?).
>Are you sure it's the server and not something related to Perl's
>handling of it?
>
Not sure at all; just a guess after some experimentation.
-- Robert
----------------------------------------
Robert Watkins
r-watkinsNO@SPAMworldnet.att.net
----------------------------------------
"I must go seek some dew-drops here,
And hang a Perl in every cowslips ear."
-- William Shakespeare
A Midsummer Night's Dream, II, i, 14
------------------------------
Date: Sun, 09 May 1999 00:41:29 GMT
From: "Charles R. Thompson" <design@raincloud-studios.com>
Subject: Re: CGI timeout in web-based listserv
Message-Id: <ZQ4Z2.1161$vP2.862@news.rdc1.tn.home.com>
>After some testing I realize I must not know what you mean.
Nah.. we're on the same wavelength here.
>I set
> $| = 1;
>before the loop, then simply called
> if ($count % 100 == 0) {
> print "$count bulletins sent<BR>\n";
> }
>from within the loop instead of the nearly 4 Kb of garbage.
Right. That's what I meant. Suprised it doens't work that way.
>This still, however, does not send anything to the browser until the
whole
>thing is done,
Hmmm. Whacky.
> which is too long for a large number of e-mail addresses (and a
>large message) as it times out after nearly 5 minutes. Am I doing it
wrong?
Nothin wrong.
Do you have anything other than a browser for HTTP? I'm talking
something that just displays the headers and print statements, etc...
what streams *into* the browser. If you did, that would be a real
quick way to see how often things come back and in what size, shape,
format.
I guess your garbage is the only option for now. Unless you could pipe
stuff off as mentioned in another message I have no more ideas. Sorry.
Unless (and this is real dumb in a clever sort of way).. your script
wrote a "processing please wait..." page to the server with a refresh
header for every 15-20 seconds pointing to itself and redirected the
browser to it before the loop begins.
Your client connection is then closed until the refresh...
Once the mail stuff completes, it would replace the page with a 'done
announcement' and no refresh header. On the next 'refresh' the page
would show as being complete and stop. That however is just a really,
really ugly way to get it done. But it would simulate the effect you
desire and eliminate the timeouts. You could even go a step farther by
printing the progress to the page on every X number of loops. Makes me
feel icky just talking about it, but it would probably work with very
little effort.
>list of 1,000 names will send less than 50 Kb to the browser, and I
sent out
Oh.. no biggie there.
CT
------------------------------
Date: Sat, 8 May 1999 22:22:03 +0100
From: "jt" <jim@printcom.ie>
Subject: CGI.pm
Message-Id: <7h29j5$b75$1@nclient3-gui.server.ntli.net>
I have installed CGI.pm into
usr/local/lib/perl5
while tring to run scripts which need this module
I get an error message as follows
Can't find string terminator "END_OF_AUTOLOAD" anywhere before EOF at
/usr/local/lib/perl5/CGI.pm line 645.
Can any one help
Also if anyone can install a web based email program called atmail
i would gladly pay
thankyou
jim@printcom.ie
------------------------------
Date: Sat, 08 May 1999 21:53:38 GMT
From: Ken MacLeod <ken@bitsko.slc.ut.us>
Subject: DOC: Using PerlSAX (a Perl binding for Simple API for XML)
Message-Id: <m3d80bcy6b.fsf@biff.bitsko.slc.ut.us>
[libxml is now available in the XML module directory on CPAN and an
announcement has been sent to c.l.p.announce. This document will be
in the next (0.02beta) release of libxml.]
=head1 Using PerlSAX
Working with PerlSAX involves using two classes (packages), a PerlSAX
parser that generates parsing events and a class that you write that
will receive those parsing events, the ``handler''. This guide will
use the XML::Parser::PerlSAX parser that uses Clark Cooper's
XML::Parser module.
The handler class implements the PerlSAX handler methods that you are
interested in. The following example, MyHandler.pm, prints a message
every time an element starts or ends:
package MyHandler;
sub new {
my ($type) = @_;
return bless {}, $type;
}
sub start_element {
my ($self, $element) = @_;
print "Start element: $element->{Name}\n";
}
sub end_element {
my ($self, $element) = @_;
print "End element: $element->{Name}\n";
}
1;
To use your handler you will need to have a script, myhandler.pl, that
loads and creates your handler and the parser, and then calls the
parser to parse the XML instance and send events to your handler:
use XML::Parser::PerlSAX;
use MyHandler;
my $my_handler = MyHandler->new;
my $parser = XML::Parser::PerlSAX->new( Handler => $my_handler );
foreach my $instance (@ARGV) {
$parser->parse(Source => { SystemId => $instance });
}
Given this XML instance, myhandler.xml:
<?xml version="1.0"?>
<article>
<title>Using PerlSAX</title>
<paragraph>Working with PerlSAX ...</paragraph>
</article>
Running myhandler.pl like this:
perl myhandler.pl myhandler.xml
will produce this output:
Start element: article
Start element: title
End element: title
Start element: paragraph
End element: paragraph
End element: article
=head2 For More Information
PerlSAX.pod is the core reference for the PerlSAX interface. Each
parser module describes it's individual capabilities.
XML::Parser::PerlSAX is the most commonly used PerlSAX implementation.
The files described in this doc are in the `examples' directory. A
more complete implementation of the very simple handler above is in
the module XML::Handler::Sample. Other, more complex handlers are in
the XML::Handler directory as well.
Another hands-on doc for PerlSAX is the XML-Parser-and-PerlSAX.pod.
This doc describes the difference between and the purpose of PerlSAX
with respect to XML::Parser.
This document was inspired by and uses the code examples from David
Megginson's ``Quick Start for SAX Application Writers.''
<http://www.megginson.com/SAX/quickstart.html>
--
Ken MacLeod
ken@bitsko.slc.ut.us
------------------------------
Date: Sat, 08 May 1999 22:25:53 GMT
From: sstarre@my-dejanews.com
Subject: Fun with lists
Message-Id: <7h2dlh$7i1$1@nnrp1.deja.com>
Having some appropriate fun today, I was exploring ways to produce unions and
interections and other logical derivations on hashes, such as %h1 U %h2. It
seemed like a great way to have fun on my day off..
In this search I accidently discovered a curious behavior on a list. I
created 2 lists and then operated on them to produce a third:
@l = (@l1 && @l2);
this assigned all of the list elements in @l2 to @l (same as this):
@l = @l2;
I thought "that's curious that it coerced a list out of the logical op which
appears to be scalar". OK, onward:
so then the next logical step (no pun intended):
@l = (@l1 || @l2);
this produced (3), the length of list @l1. Why would the OR treat the lists in
the scalar sense, while the AND in the non-scalar sense? The only difference I
see is that one short-circuits, the other doesn't.
Another curiosity- if list @l1 is SHORTER than list @l2, ANDing them still
produces @l2. I wonder what its ANDing the elements to, after they run out in
@l1!
Ahh Perl..
Back to the fun..
HUG
-S
PS: Hey Larry, overload a mess of operators to give us more hash functions,
like %h1 + %h2 would produce a hash of elements in h2 OR h2.. and so on..
Writing loops to do this is EZ but overloading is more elegante..
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 8 May 1999 23:59:50 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Fun with lists
Message-Id: <7h2j5m$464$1@gellyfish.btinternet.com>
On Sat, 08 May 1999 22:25:53 GMT sstarre@my-dejanews.com wrote:
>
>
> In this search I accidently discovered a curious behavior on a list. I
> created 2 lists and then operated on them to produce a third:
>
> @l = (@l1 && @l2);
>
> this assigned all of the list elements in @l2 to @l (same as this):
>
> @l = @l2;
>
> I thought "that's curious that it coerced a list out of the logical op which
> appears to be scalar". OK, onward:
>
Yep.
What you are seeing here is that @l1 is being taken in a scalar context
(giving its length ) and because this is true the thing in the brackets takes
the value of the second array. If the first array had no elements then
the value of this would have been 0.
> so then the next logical step (no pun intended):
>
> @l = (@l1 || @l2);
>
> this produced (3), the length of list @l1. Why would the OR treat the lists in
> the scalar sense, while the AND in the non-scalar sense? The only difference I
> see is that one short-circuits, the other doesn't.
>
Yep. This is really the other way round from the above.
Because the first value is true then the second is not evaluated - thus
the value of the assignment is the length of the first array - if the
first array had no elements then the assignment would be of the contents
of second array.
/J\
--
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Sat, 08 May 1999 23:50:11 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Fun with lists
Message-Id: <3734CD48.D6D55AC0@home.com>
[posted & mailed]
sstarre@my-dejanews.com wrote:
>
> In this search I accidently discovered a curious behavior on a list. I
> created 2 lists and then operated on them to produce a third:
>
> @l = (@l1 && @l2);
>
> this assigned all of the list elements in @l2 to @l (same as this):
>
> @l = @l2;
>
> I thought "that's curious that it coerced a list out of the logical op which
> appears to be scalar". OK, onward:
Yes, as documented in perlop.
=head2 C-style Logical And
Binary "&&" performs a short-circuit logical AND operation. That is,
if the left operand is false, the right operand is not even evaluated.
Scalar or list context propagates down to the right operand if it
is evaluated.
> so then the next logical step (no pun intended):
>
> @l = (@l1 || @l2);
>
> this produced (3), the length of list @l1. Why would the OR treat the lists in
> the scalar sense, while the AND in the non-scalar sense? The only difference I
> see is that one short-circuits, the other doesn't.
Yup. Make @l1 the empty list and try again. Now && will short circuit
instead. There is more explanation using this example in perlop,
"C-style Logical Or".
> Another curiosity- if list @l1 is SHORTER than list @l2, ANDing them still
> produces @l2. I wonder what its ANDing the elements to, after they run out in
> @l1!
It is not &&-ing each element of the array. The truth of the left
operand is tested (i.e. whether it is an empty array or not) and then
evaluating the right operand (i.e. returning the list) if necessary.
perldoc perlop
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: Sat, 8 May 1999 17:26:34 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Fun with lists
Message-Id: <MPG.119e7611339e201e989a15@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <7h2dlh$7i1$1@nnrp1.deja.com> on Sat, 08 May 1999 22:25:53
GMT, sstarre@my-dejanews.com <sstarre@my-dejanews.com> says...
> Having some appropriate fun today, I was exploring ways to produce unions and
> interections and other logical derivations on hashes, such as %h1 U %h2. It
> seemed like a great way to have fun on my day off..
>
> In this search I accidently discovered a curious behavior on a list. I
> created 2 lists and then operated on them to produce a third:
>
> @l = (@l1 && @l2);
>
> this assigned all of the list elements in @l2 to @l (same as this):
>
> @l = @l2;
>
> I thought "that's curious that it coerced a list out of the logical op which
> appears to be scalar". OK, onward:
perlop: C-style Logical And
Binary ``&&'' performs a short-circuit logical AND operation. That is,
if the left operand is false, the right operand is not even evaluated.
Scalar or list context propagates down to the right operand if it is
evaluated.
The left operand is true, so the right operand is evaluated in list
context.
> so then the next logical step (no pun intended):
>
> @l = (@l1 || @l2);
>
> this produced (3), the length of list @l1. Why would the OR treat the lists in
> the scalar sense, while the AND in the non-scalar sense? The only difference I
> see is that one short-circuits, the other doesn't.
C-style Logical Or
Binary ``||'' performs a short-circuit logical OR operation. That is, if
the left operand is true, the right operand is not even evaluated.
Scalar or list context propagates down to the right operand if it is
evaluated.
The left operand is true, and its value is 3, which becomes the first
and only list element.
> Another curiosity- if list @l1 is SHORTER than list @l2, ANDing them still
> produces @l2. I wonder what its ANDing the elements to, after they run out in
> @l1!
The contents of @l1 never enter into it -- just that there *be* any!
> Ahh Perl..
> Back to the fun..
>
> HUG
>
> -S
>
> PS: Hey Larry, overload a mess of operators to give us more hash functions,
> like %h1 + %h2 would produce a hash of elements in h2 OR h2.. and so on..
> Writing loops to do this is EZ but overloading is more elegante..
>From Another Larry: Hash slices are your friend. (See Uri Gellman's
recent postings.)
my %h3;
@h3{ keys(%h1), keys(%h2) } = (values(%h1), values(%h2));
Not a loop in sight!
The values of keys in %h2 overwrite the values of identical keys in %h1.
Have fun working out the AND or any other operations.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 8 May 1999 21:02:42 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Net::SMTP Problems. Help !
Message-Id: <7h28pi$3vd$1@gellyfish.btinternet.com>
On Sat, 8 May 1999 12:25:04 -0700 Steven McPherson wrote:
> Hi-
>
> I seem to have problems with the Net::SMTP module included with LibNet.
You don't have problems with Net::SMTP
> D:\Documents and Settings\stevenmc\My Documents\perl>mail.pl
> In string, @there now must be written as \@there at D:\Documents and
> Settings\st
> evenmc\My Documents\perl\mail.pl line 12, near "To: user@there"
When you get a diagmostice message from Perl like this you should
always look in the perldiag manpage to see what it means :
In string, @%s now must be written as \@%s
(F) It used to be that Perl would try to guess whether
you wanted an array interpolated or a literal @. It
did this when the string was first used at runtime.
Now strings are parsed at compile time, and ambiguous
instances of @ must be disambiguated, either by
prepending a backslash to indicate a literal, or by
declaring (or using) the array within the program
before the string (lexically). (Someday it will
simply assume that an unbackslashed @ interpolates an
array.)
Infact the message was fairly clear.
/J\
--
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Sat, 08 May 1999 22:05:33 GMT
From: sstarre@my-dejanews.com
Subject: Re: Perl in the workplace
Message-Id: <7h2cfc$6j6$1@nnrp1.deja.com>
Hello there Cameron:
Thaank-You for this nice reply.
I just previewed your site - what wonderful work! I'm going to read it
thouroughly tonight. I like the format too. I have to go my dictionary site
now to look up ubiquitious though...
You're quite right I'm not all that concerned with their policies anymore. My
next employer will be Perl-friendly :)
As for the details on the VB script- what I saw (I never actually had to CODE
the stuff) it looked like javascript as far as the implementation- it was
inline with the HTML. Otherwise I'm told it was pretty much like regular old
VB, just used inline instead..
I just previewed your site - what wonderful work! I'm going to read it
thouroughly tonight. I like the format too. I have to go my dictionary site
now to look up ubiquitious though...
Here is my new sig- whatya think?
*****************************************
* Cast not Perl before Microsoft swine..*
* -S Starre 1999 *
*****************************************
In article <7h0k25$mml$1@Starbase.NeoSoft.COM>,
claird@Starbase.NeoSoft.COM (Cameron Laird) wrote:
> In article <7gk54k$q9a$1@nnrp1.dejanews.com>, <sstarre@my-dejanews.com>
wrote:
> >
> >
> >
> >I work for a large Fortune company, where use of Perl is a forbidden
> >practice. There are two distinct camps - MIS, who mandates that all CGI will
> >be done in VB-script (ack!), and two, engineers and scientists who use an
> >ecclectic mix of languages. In my camp (the latter) a small band of us risk
> I'm curious--it's not *really* VBScripted CGI, is
> it? I suspect they're actually using ASP coded in
> VBScript--true?
> .
> .
> .
> >Do others find this kind of resistance to Perl at work? If so, were you able
> >to make a case to management to at least allow it as a "2nd language"? Have
> >you had to "go underground" to get your job done?
> I understand that the policies of this employer are
> no longer of practical concern to you. More gener-
> ally, though, I'm working on <URL:http://
> starbase.neosoft.com/~claird/comp.lang.perl.misc/PerlWhitePaper.html>
> which I hope will help in some of these situations.
>
> Tom's FAQs are also top-notch sources for helpful
> material.
> .
> .
> .
> --
>
> Cameron Laird http://starbase.neosoft.com/~claird/home.html
> claird@NeoSoft.com +1 281 996 8546 FAX
>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Sat, 08 May 1999 16:55:07 -0500
From: Ed Lake <writer@wi.net>
Subject: Re: Rejecting unwanted hits
Message-Id: <3734B2BB.DF8EE874@wi.net>
Jonathan Stowe wrote:
> On Sat, 08 May 1999 09:09:46 -0500 Ed Lake wrote:
> > Jonathan Stowe wrote:
> >
> >> On Fri, 07 May 1999 16:45:06 -0500 Ed Lake wrote:
> >> > I'm looking for a way to reject hits on my web site that come from links
> >> > on certain other web sites. Someone told me that it can be done by
> >> > inserting some PERL code into the index.cgi file.
> >> >
> >>
> >> I'm sure that its entirely possible
> >>
>
> <snip>
>
> >> Yes there is a FAQ but unfortunately it isnt for this group :
> >>
> >> <http://www.webthing.com/tutorials/cgifaq.html>
> >>
> >> The group in question is :
> >>
> >> comp.infosystems.www.authoring.cgi
> >>
> >
> > Basically, all I want to do is reject hits coming from links on two specific
> > sites, while letting everyone else in the world through.
> >
>
> Yeah but this is still basically a CGI question that should be asked in
> the appropriate group - However a quick hack would be:
>
> use CGI qw(:standard);
>
> if (referer() =~ /www.blah.com/ )
> {
> # do whatever
> print redirect('http://www.microsoft.com');
> }
> else
> {
> # thats fine ....
> }
>
> /J\
> --
> Jonathan Stowe <jns@gellyfish.com>
> Some of your questions answered:
> <URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
> Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
Jonathan,
Thanks again. Unfortunately, news:comp.infosystems.www.authoring.cgi doesn't seem
to be a newsgroup available on my news server. Is it something special like the
Netscape newsgroups that you can only access via the Netscape web site? I get
30,000 newsgroups, but not that one. It's not on either one of the two news
servers I use.
Ed
------------------------------
Date: Sun, 09 May 1999 00:44:11 GMT
From: "Charles R. Thompson" <design@raincloud-studios.com>
Subject: Re: Rejecting unwanted hits
Message-Id: <vT4Z2.1162$vP2.868@news.rdc1.tn.home.com>
>Thanks again. Unfortunately, news:comp.infosystems.www.authoring.cgi
doesn't seem
>to be a newsgroup available on my news server. Is it something
special like the
>Netscape newsgroups that you can only access via the Netscape web
site? I get
>30,000 newsgroups, but not that one. It's not on either one of the
two news
>servers I use.
I find that almost impossible to fathom. Out of *30,000* groups that
one is gone? Did you look for only...
comp.infosystems.www.authoring.cgi
and not the news part? (Sorry... gotta ask)
This baffles the heck out of me.
CT
------------------------------
Date: Sat, 8 May 1999 16:51:14 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Sorting is too slow for finding top N keys... - UPDATE
Message-Id: <MPG.119e6dcfb2e6900c989a14@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <7h260m$t07$1@xenon.inbe.net> on Sat, 08 May 1999 20:16:09
GMT, Michel Dalle <michel.dalle@usa.net> says...
> In article <7h24na$sfp$1@xenon.inbe.net>, michel.dalle@usa.net (Michel Dalle) wrote:
...
> >Here's what happened : I have a hash with about 30.000 entries,
> >I want to sort them by value and extract the top N elements.
> >The hash contains about 500 different values, and the majority
> >of values are all the same (=heavy-tailed distribution?).
...
> 3) forget about the sort in Perl, and build my own :
>
> @topn = ();
> $count = 0;
> while (($key,$val) = each %hash) {
> if ($count <= $n) {
> push(@topn,$key);
> if ($count == $n) {
> @topn = (sort {$hash{$b} <=> $hash{$a}} @topn);
> }
> }
> else {
> if ($val > $hash{$topn[0]}) {
> pop(@topn);
> unshift(@topn,$key);
> }
> elsif ($val < $hash{$topn[$n]}) {
> }
> else {
> for ($i = 1; $i < $n; $i++) {
> if ($val > $hash{$topn[$i]}) {
> last;
> }
> }
> splice(@topn,$i,0,$key);
> pop(@topn);
> }
> }
> $count++;
> }
>
> This one sorts my 30.000+ hash in 3 seconds, the previous one in 45 seconds,
> and the first one in xxx minutes, for a top 20.
>
> Any comments ?
Yes.
The complexity of the Perl quicksort is O(M log M) where M is the number
of elements in the hash (you said about 30_000).
The complexity of your repeated insertion sorts is O(M N**2) where N is
the number of elements in the topN list (you said 20).
Clearly, for large enough M and small enough N, your algorithm will be
faster than sorting the entire input and selecting the top N elements.
Equally clearly, your M is large enough and your N is small enough. :-)
Just for fun, I recoded your algorithm a bit more compactly. It seems
to work fine with small artificial data sets. I'd be interested in how
it works on your big hash.
#!/usr/local/bin/perl -w
use strict;
my %hash;
@hash{ 'a' .. 'z', 'A' .. 'Z' } = ( 1 .. 26, 1 .. 26 );
print topN(\%hash, 20), "\n";
sub topN {
my ($href, $n) = @_;
my @topn;
while (my ($key, $val) = each %$href) {
@topn or @topn = $key, next; # to get started
next if $val < $href->{$topn[-1]};
my $i = 0;
++$i while $val < $href->{$topn[$i]};
splice @topn, $i, 0, $key;
--$#topn if @topn > $n;
}
@topn # short enough to return the list, not a ref
}
__END__
Yum. That looks like something for the Perl Function Repository. If
time permits, I'll write up the description and submit it, with due
credit for your ideas.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 8 May 1999 22:30:23 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: SRC: There be dragons
Message-Id: <7h2dtv$42c$1@gellyfish.btinternet.com>
<Subject line for Matthew>
Oh there had to be more didnt there ?
I have checked out <real> between 1.415414 and 3.018153
<imaginary> between -0.924069 and 0.967049
and generally <scale> around 1
Well Robocop only takes up some of my attention ...
#!/usr/bin/perl -w
use strict;
use GD;
use vars qw($magnitude);
my ($x_centre,$y_centre) = (320,175);
if ( scalar @ARGV < 3 )
{
die <<EEE;
usage : $0 <real> <imaginary> <scale>
EEE
}
my ($P,$Q,$scale) = @ARGV;
my $image = new GD::Image($x_centre * 2,$y_centre * 2);
my $back_colour = $image->colorAllocate(255,255,255);
my $fore_colour = $image->colorAllocate(0,0,0);
my ($x,$y) = (0.50001,0);
$magnitude = ($P*$P) + ($Q*$Q);
$P = 4*$P/$magnitude;
$Q = -4*$Q/$magnitude;
$scale = $x_centre * $scale;
for ( 1 .. 12000 )
{
my $temp_x = ($x * $P ) - ($y * $Q );
$y = ($x * $Q) + ($y * $P );
my $temp_y = $y;
$x = 1 - $temp_x;
$magnitude = sqrt(($x * $x ) + ($y * $y));
$y = sqrt((-$x + $magnitude)/2);
$x = sqrt(($x + $magnitude)/2);
($x = -$x) if ($temp_y < 0 );
if ( rand() < 0.5 )
{
$x = -$x;
$y = -$y;
}
$x = (1- $x) / 2;
$y = $y / 2;
my $col = int(($scale * ($x - 0.5 )) + $x_centre);
my $row = int($y_centre - ($scale * $y));
if ( ($_ > 0 ) &&
($col >= 0 ) &&
($col < (2 * $x_centre)) &&
($row >= 0 ) &&
($row < ($y_centre * 2 )))
{
$image->setPixel($col,$row,$fore_colour);
}
}
open(GIF,">image$$.gif") || die "Cannot open output - $!\n";
binmode(GIF);
print GIF $image->gif;
close(GIF);
__END__
/J\
--
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Sat, 08 May 1999 22:34:21 GMT
From: epement@jpusa.chi.il.us (Eric Pement)
Subject: Re: tcgrep not expanding command-line wildcards
Message-Id: <3734ba80.29815014@news.jpusa.net>
On Fri, 7 May 1999 23:21:14 GMT, Eric Bohlman <ebohlman@netcom.com>
wrote:
>Eric Pement <epement@jpusa.chi.il.us> wrote:
[...]
>: perl -ne "print if /match/" tc*.*
>
>: generating this error message:
>
>: Can't open tc*.*: No such file or directory
>
>: This behavior definitely did not occur with build 315, nor with earlier
>: versions of Perl for DOS. Has anyone noticed this problem before? Any
>: suggested fixes?
>
>The 300-series builds incorporated built-in (transparent) command-line
>glob expansion. The more recent versions don't, but there's a workaround
>as shown in this rather old message from Gurusamy Sarathy:
[... omitted ...]
Thanks for letting me know about this. I was surprised to think that
any version of Perl running on a Win32 system WOULDN'T automatically
support ambiguous filespecs (or "filename globbing" as they say now).
Given that the installation program knows its running under Windows, and
not under (say) bash or tcsh, I would think it ought to add the glob
expansion automatically.
I've appreciated your help from the old CP/M and Kaypro days.
Kind regards,
Eric Pement
--
Eric Pement <epement@jpusa.org>
senior editor, Cornerstone magazine
http://www.cornerstonemag.com
939 W. Wilson, Chicago, IL 60640
tel: 773/561-2450, 1-(ext.)2084 fax: 773/989-2076
------------------------------
Date: Sat, 08 May 1999 23:35:02 GMT
From: smith157@marshall.edu (KaledBait)
Subject: Re: Telnet module and perl script to telnet to remote, perform commands and log output
Message-Id: <3736c805.12012554@news.fuse.net>
On 8 May 1999 12:48:26 -0000, Jonathan Stowe <gellyfish@gellyfish.com>
wrote:
>On Fri, 07 May 1999 22:17:11 GMT KaledBait wrote:
>> I am attempting to write a perl script that will connect to a
>> remote host via telnet, login, perform a couple of commands, log the
>> output generated by those commands and then logoff.
>> In a previous post a few weeks ago I noticed someone mention
>> there is a telnet module that will allow you to perform commands on a
>> remote host.
>
>That module will be Net::Telnet which is available from all participating
>branches of CPAN.
>
>/J\
I have the module now and have been to trying to write a very simple
program to ensure I can use the module which is as follows
#!/usr/bin/perl
push (@INC, '/home/dlt/perl/');
use Telnet ();
&blah = new Telnet();
I have the Telnet.pm in the /home/dlt/perl directory.
When I run this script I get the following error.
Can't modify subroutine entry in scalar assignment at ./test2.pl line
4, near ");"
Execution of ./test2.pl aborted due to compilation errors.
I'm pretty new to Perl and this isn't making sense to
me......Heeeeeeeelp
KaledBait - smith157ATmarshall.edu
------------------------------
Date: Sat, 08 May 1999 16:26:12 -0500
From: Paul Phillips <pcphil@cyberramp.net>
Subject: trouble building perl on solaris
Message-Id: <E1AD8986DD0FAC34.EDE0C36A379FC89A.7C8EB09949485FD3@library-proxy.airnews.net>
My setup - Sparcbook 3GX with Solaris 2.5.1 installed.
When I try to make perl 5.005_03 on my Solaris machine, the bake dies
with the following message:
gcc -B/usr/ccs/bin/ -c -I/usr/local/include -O -DVERSION=\"1.03\"
-DXS_VERSION=\"1.03\" -I../.. -DPERL_CORE -DLIBC="/lib/libc.so"
DynaLoader.c
rm -rf ../../lib/auto/DynaLoader/DynaLoader.a
ar cr ../../lib/auto/DynaLoader/DynaLoader.a DynaLoader.o && :
../../lib/auto/DynaLoader/DynaLoader.a
/bin/sh: ar: not found
make[1]: *** [../../lib/auto/DynaLoader/DynaLoader.a] Error 1
make[1]: Leaving directory
`/export/home/paul/perl5.005_03/ext/DynaLoader'
make: *** [lib/auto/DynaLoader/DynaLoader.a] Error 2
I invoke the sh Configure script with the following command:
sh Configure -Dcc = 'gcc -B/usr/ccs/bin' -Dar=/usr/ccs/bin/ar
Configure seems to work fine - I just select all the defaults.
I know the following:
1) /usr/ccs/bin IS in my path
2) /usr/ccs/bin/ar IS really there - I checked. (I installed is from
the package on the Solaris CD.
3) Configure finds ar when it is looking around at the beginning of the
Configure script!
So why does the make die, and say it can't find ar.
Can anyone help?
Thanks,
Paul Phillips
------------------------------
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 5607
**************************************