[10814] in Perl-Users-Digest
Perl-Users Digest, Issue: 4415 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Dec 13 19:07:15 1998
Date: Sun, 13 Dec 98 16:00:21 -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: 4415
Today's topics:
2 questions ... <darrensweeney@eswap.co.uk>
Re: 2 questions ... (Matthew Bafford)
Re: 80 column conversion (John Moreno)
Beginner: What's wrong? <mhol003@stat.auckland.ac.nz>
Re: Beginner: What's wrong? <kprice@cardinal.co.nz>
Can't get counter Perl scripts to run under NT4 <adrian@pearl.demon.co.uk>
Re: Flock <merlyn@stonehenge.com>
Re: Flock (Tad McClellan)
Re: Flock <support@counter.w-dt.com>
Re: Flock (Martien Verbruggen)
Re: getting http-referer <postmaster@castleamber.com>
how can I get this hash references? (Josi)
Re: how can I get this hash references? <rick.delaney@home.com>
How do I allow File-uploading into database cgi@higherlove.com
Multiple logins with AuthenDBI!?! <eivindtr@ah.telia.no>
perl and scientific applications <bruce.ravel@nist.gov>
Re: perl and scientific applications (Brian D. Schieber)
Processing Incoming Mail? (Mike Watkins)
script for choosing headers in mail (was: Re: script f| <NFilus@gmx.net>
Re: Sorting problem: Is there a better way? (Larry Rosler)
Re: Sorting problem: Is there a better way? (Larry Rosler)
Upload files CGI.pm and HTTP::Daemon <roycych@hotmail.com>
Re: Using perl5 with Win95/dos command line. (Tony Cook)
Re: Writing Perl with Notepad (Bart Lateur)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 13 Dec 1998 14:25:14 -0800
From: "E-swap" <darrensweeney@eswap.co.uk>
Subject: 2 questions ...
Message-Id: <751f0b$pj6@sjx-ixn5.ix.netcom.com>
Hi
Firstly, can I fake a browser command line?
I have a search on my site. From that search result a link is created to
view the item.
What I want to happen is that if the search only has one item as a result, I
want the search to go straight to view the item. So, I need it to instead of
print the results list of one item, go instead straight to:
http://www.blahblah.com/cgi-bin/view.cgi?1&viewitem&resultitemnumber
The search is one script and the item viewer is another.
Secondly, I want to create a different page to be displayed when, and if,
the user gets a dreaded Internal server Error message, can I redirect the
error to pull up a different page?
Thanks for all help ...
Darren
------------------------------
Date: Sun, 13 Dec 1998 17:45:28 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: 2 questions ...
Message-Id: <MPG.10de0d97c057ea8898975f@news.scescape.net>
In article <751f0b$pj6@sjx-ixn5.ix.netcom.com>, darrensweeney@eswap.co.uk
says...
=> Hi
=>
=> Firstly, can I fake a browser command line?
[snip]
Look for the LWP modules (from www.perl.com/CPAN/ if using a non-windows
port, from www.activestate.com otherwise).
Depending on how involved you want to get, this can be as simple as:
#!/usr/bin/perl -w
use LWP::Simple;
getprint("http://www.yahoo.com");
__END__
=> Secondly, I want to create a different page to be displayed when, and if,
=> the user gets a dreaded Internal server Error message, can I redirect the
=> error to pull up a different page?
Server dependent, and has absolutely nothing to do with Perl.
=> Thanks for all help ...
HTH!
=> Darren
--Matthew
------------------------------
Date: Sun, 13 Dec 1998 15:20:20 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: 80 column conversion
Message-Id: <1djzdpw.dtby581igo07qN@roxboro0-031.dyn.interpath.net>
Jaya_Kanajan <jkanajan@ets.cis.brown.edu> wrote:
> I would like to add something to my code that will take any sequence of
> greater then three carriage returns/newlines and replace it with a single
> newline.
#warning -- untested code.
if ($_ eq "\n") {
$_=<CODE>;
if ($_ eq "\n") {
$_=<CODE>;
if ($_ eq "\n") {
while ($_ eq "\n") {
$_=<CODE>;
}
print OUT "\n:;
} else {
print "\n\n";
}
} else {
print "\n";
}
}
--
John Moreno
------------------------------
Date: Mon, 14 Dec 1998 11:25:00 +1300
From: Mark Holmes <mhol003@stat.auckland.ac.nz>
Subject: Beginner: What's wrong?
Message-Id: <36743EBC.4535B2DD@stat.auckland.ac.nz>
My simple loop only produces one file (corresponding to i=j=0 - it does
the correct thing in this case). Can anyone see the problem? I'm sure
it's glaringly obvious, but I can't see it! Thanks in advance :-) !
for($i=0;$i<12;$i++){
for($j=0;$j<13;$j++){
$x=60*$j;$y=60*$i;
exec("pnmcut $x $y 60 60 testgif.pnm | ppmtogif > icon$i$j.gif");}}
--
When I found the skull in the woods, the first thing I did was call the
police. But then I got curious about it. I picked it up, and started
wondering who this person was, and why he had deer horns.
------------------------------
Date: Mon, 14 Dec 1998 11:40:38 +1300
From: Kelvin Price <kprice@cardinal.co.nz>
Subject: Re: Beginner: What's wrong?
Message-Id: <36744266.7897C585@cardinal.co.nz>
Mark Holmes wrote:
>
> My simple loop only produces one file (corresponding to i=j=0 - it does
> the correct thing in this case). Can anyone see the problem? I'm sure
> it's glaringly obvious, but I can't see it! Thanks in advance :-) !
Indeed it is ! 8-D
>
> for($i=0;$i<12;$i++){
> for($j=0;$j<13;$j++){
> $x=60*$j;$y=60*$i;
> exec("pnmcut $x $y 60 60 testgif.pnm | ppmtogif > icon$i$j.gif");}}
>
I really don't think you want exec there. Read about exec and you
should be able to work out why your command only runs once. Then read
about system(), backticks and/or qx.
------------------------------
Date: Sun, 13 Dec 1998 15:13:10 +0000
From: Adrian Albin-Clark <adrian@pearl.demon.co.uk>
Subject: Can't get counter Perl scripts to run under NT4
Message-Id: <H0nnnLAGm9c2EwSe@pearl.demon.co.uk>
I'm an A level IT lecturer at a college in England and my students are
completing web projects for me.
In order to get decent grades they are supposed to make their sites
interactive.
I have already used Matt Wright's excellent guestbook.pl script, which I
amended for my own needs.
I would like to use a counter script for their pages also but as yet
have had no luck finding one that will work under my current setup at
home (which is the same as at college).
I have seen all sorts of references to SSI, and see your network
administrator etc. but
a) none of the SSI references seem to relate to NT
b) the system administrator at my college knows nothing about SSI or
server side scripting (perl, cgi etc)
Could you please help or point me in the direction of someone/somewhere
that is useful.
TO SUMMARISE
*********************************************************************
I need a text (or graphics if possible) counter to run on an Intranet
under NT4 using IIS2 with the latest ActivePerl for Win32 running. It
will need to accomodate more than one page as all my students will need
to use the counter.
I need to know how to configure the web server to run such a script
(i.e. will a default install of IIS2 and ActivePerl be enough?)
I need to know how to call the script from within a web page.
PLEASE HELP!!!
--
Adrian Albin-Clark
------------------------------
Date: Sun, 13 Dec 1998 20:01:19 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: Flock
Message-Id: <8ck8zvrev3.fsf@gadget.cscaper.com>
>>>>> "Mike" == Mike <support@counter.w-dt.com> writes:
Mike> Why do you call flock after you open the file and not before?
[why do you cc me blindly (arguguughg!) Please don't do that again.
Either don't cc me, or say it's a cc. I'm now RETYPING all this stuff
that I had sent you private email. Bleh.]
You call flock after open because you cannot flock a closed filehandle!
--
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 16:01:28 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Flock
Message-Id: <ofd157.6j1.ln@magna.metronet.com>
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...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 13 Dec 1998 16:48:30 -0600
From: Mike <support@counter.w-dt.com>
Subject: Re: Flock
Message-Id: <3674443D.1A77FD7D@counter.w-dt.com>
I looked at many docs, somepeople would say if you don't want to help, without
being snobbish, get the hell off the news group. A news group is where people
go for help. I looked up in many perl books, just because it has flock
(filehandle, 2); to me doesn't just come out and say it has to go after open.
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...
>
> --
> Tad McClellan SGML Consulting
> tadmc@metronet.com Perl programming
> Fort Worth, Texas
------------------------------
Date: Sun, 13 Dec 1998 23:11:39 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Flock
Message-Id: <LQXc2.38$SU4.175@nsw.nnrp.telstra.net>
In article <3674443D.1A77FD7D@counter.w-dt.com>,
Mike <support@counter.w-dt.com> writes:
> I looked at many docs, somepeople would say if you don't want to
> help, without being snobbish, get the hell off the news group. A
> news group is where people go for help. I looked up in many perl
> books, just because it has flock (filehandle, 2); to me doesn't just
> come out and say it has to go after open.
He's not being snobbish. He's telling you to read the documentation,
and he's doing you a favour by that.
Newsgroups are not places where people can go to get help whenever
they want. Newsgroups are forums where people discuss a topic of
interest they have in common. In this particular case that is the Perl
programming language. What you are thinking of is called a help desk,
and that is certainly not what we are.
For this particular case: If you had read the flock entry in the
perlfunc documentation (perldoc -f flock, or perldoc perlfunc, or man
perlfunc, or click on your link in your browser), and you would have
read through to the end, you would have seen the example that shows
you how and where it is used.
Besides that, as Tad pointed out, the specification of flock mentions
that you need a file handle as its first argument. You need to open
one for that first.
We are not here to hold your hand while you are exploring perl. We are
not here to read the documentation for you. We are here to discuss
Perl, and helping people out with problems is something that is not
our main task or goal in life. We do it, but that;s not why we are
here. If you need that, pay someone for it.
*plonk*
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | Very funny Scotty, now beam down my
Commercial Dynamics Pty. Ltd. | clothes.
NSW, Australia |
------------------------------
Date: 13 Dec 1998 21:09:12 GMT
From: "John Bokma" <postmaster@castleamber.com>
Subject: Re: getting http-referer
Message-Id: <01be26dc$7b8ab0e0$02521e0a@tschai>
marshman <nospamm@deleteme> wrote in article
<74ujti$7p7$1@camel19.mindspring.com>...
> $refer = $ENV{'HTTP_REFERER'};
>
> open (LOGFILE, ">> mylog");
> print LOGFILE "$refer";
> close (LOGFILE);
>
> You should check out file locking (flock)!!!!
AFAIK, locking is *not* needed when you *append*
to a file (single line), it's an atomic operation.
BTW:
#!/usr/local/bin/perl -w
use strict;
my $refer = $ENV{HTTP_REFERER};
$refer = "not given" unless defined $refer;
if (open(LOGFILE, ">>mylog"))
{
print LOGFILE "$refer\n";
close(LOGFILE)
}
Or even beter, if you have your own access_log and
use Apache check out http://www.apache.org/ and
configure the server to use the extended log format.
(or convince your webspace provider to do so)
John
--
------------------------------------------------------------------
C A S T L E A M B E R Software Development (Java/Perl/C/CGI)
http://www.castleamber.com/ john@castleamber.com
http://www.caiw.nl/~jbokma/
http://www.binaries.org/ Guide to Program Binaries and Pictures
------------------------------
Date: Sun, 13 Dec 1998 19:53:41 GMT
From: j123ender123@gmx.net (Josi)
Subject: how can I get this hash references?
Message-Id: <3674149e.2855115@news.active.ch>
Hi all
I try to get shared resources from remote Win32 hosts with the
function:GetSharedResources(\@Resources,dwType) from the
Win32::NetResource modul.
Now I don't know how I can get this resources.
I found only the following sentence in the help:"Creates a list in
@Resources of %NETRESOURCE hash references."
In the Array @Resources I have some values like this:
HASH(0x88bce0)HASH(0x893454)
How can I get the real list of shared resources now?
I'm very grateful for every help!
Josi
------------------
I don't like spam!
If you reply by e-mail please remove "123" from my address.
------------------------------
Date: Sun, 13 Dec 1998 21:45:35 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: how can I get this hash references?
Message-Id: <36743738.3CC33666@home.com>
Josi wrote:
>
> Hi all
>
> I try to get shared resources from remote Win32 hosts with the
> function:GetSharedResources(\@Resources,dwType) from the
> Win32::NetResource modul.
> Now I don't know how I can get this resources.
> I found only the following sentence in the help:"Creates a list in
> @Resources of %NETRESOURCE hash references."
>
> In the Array @Resources I have some values like this:
> HASH(0x88bce0)HASH(0x893454)
>
> How can I get the real list of shared resources now?
Well, the structure of %NETRESOURCE is documented in said module so I'm
guessing that you just don't know how to dereference a hash ref?
Try this:
for my $netresource (@Resources) { # each resource
while (my ($key, $val) = each %$netresource) { # each property
print "$key => $val\n";
}
}
print "$Resources[0]{DisplayType}\n";# a property of a specific
# resource
Then read perlref and perldsc for more on references and data
structures.
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: Sun, 13 Dec 1998 22:50:21 GMT
From: cgi@higherlove.com
Subject: How do I allow File-uploading into database
Message-Id: <36744459.92860490@news.phnx.uswest.net>
I want to allow users to upload graphics into an field in a
ASCII-based database file. Anywhere I can find out how to do this?
Thanks!
------------------------------
Date: Sun, 13 Dec 1998 20:33:32 +0100
From: Eivind Trondsen <eivindtr@ah.telia.no>
Subject: Multiple logins with AuthenDBI!?!
Message-Id: <3674168C.ADF11611@ah.telia.no>
Hi all
I have a peculiar problem with Apache/DBI. I want to use both
Apache::DBI and Apache::AuthenDBI, like many others I guess. Now, what
happens to me is that AuthenDBI opens an additional session with the
database even if the Apache child already got a login.
So now I sit here with twice the number of logins required, and that is
bad when I have more than 100 processes to serve in the production
environment.
Any hints on what I do wrong? I run Sybase ASE and Apache 1.3.1+mod_perl
1.15 on a 2.0.36 linux.
Here are my setup files
In access.conf:
# mod_perl setup
Perlrequire /www/share/perl-init/start.pl
PerlFreshRestart on
This is the required file:
use strict;
use Carp;
use CGI;
use IPC::Shareable;
use Apache::DBI;
use Apache::AuthenDBI;
# I have tried with this on and off
# Apache::DBI->connect_on_init('SYBASE', 'someone', 'SomeTh1ng',
'Sybase');
use Apache::Registry;
use HTML::Embperl;
+ much else not relevant
The .htacccess in the directory with access control:
AuthName DBI
AuthType Basic
#authenticate via DBI
PerlAuthenHandler Apache::AuthenDBI
PerlSetVar Auth_DBI_data_source dbi:Sybase:SYBASE
PerlSetVar Auth_DBI_username someone
PerlSetVar Auth_DBI_password SomeTh1ng
PerlSetVar Auth_DBI_pwd_table USERS
PerlSetVar Auth_DBI_uid_field UNAME
PerlSetVar Auth_DBI_pwd_field PASSWORD
PerlSetVar Auth_DBI_encrypted off
<Limit GET POST>
require valid-user
</Limit>
I bet there is a really simple solution. There always is.....
Anyway; I'll much appreciate help.
/Eivind Trondsen
------------------------------
Date: 13 Dec 1998 16:21:23 -0500
From: Bruce Ravel <bruce.ravel@nist.gov>
Subject: perl and scientific applications
Message-Id: <m3k8zvlovg.fsf@h196101.nist.gov>
As a part of my research, I am writing some perl code to perform
crystallographic calculations. The heart of the crystallography code
has been written as a reusable, object oriented perl module -- just
the way such things should be done in perl!
I am considering offering my work to CPAN and one of the things
suggested on the PAUSE page is to solicit some public discussion, so
here goes...
Is there anyone out there who would be interested in using a
crystallography module?
Is there anyone out there who would be willing to test my work? (It
is pretty servicable at this time.)
Is there anyone out there with some wisdom to offer regarding
scientific applications of perl and submission to CPAN?
Thanks!!
Bruce
--
Bruce Ravel ---------- bruce.ravel@nist.gov or ravel@phys.washington.edu
National Institute of Standards and Technology | Office: Room B356
Bldg 223, Room A215, Gaithersburg, MD 20899 USA | ph: 301-975-5759
http://feff.phys.washington.edu/~ravel | fax: 301-975-5334
------------------------------
Date: 13 Dec 1998 22:11:31 GMT
From: schieb@seabass.gsfc.nasa.gov (Brian D. Schieber)
To: Bruce Ravel <bruce.ravel@nist.gov>
Subject: Re: perl and scientific applications
Message-Id: <751e2j$dom@post.gsfc.nasa.gov>
In article <m3k8zvlovg.fsf@h196101.nist.gov>, Bruce Ravel <bruce.ravel@nist.gov> writes:
|>
|> As a part of my research, I am writing some perl code to perform
|> crystallographic calculations. The heart of the crystallography code
|> has been written as a reusable, object oriented perl module -- just
|> the way such things should be done in perl!
|>
|> I am considering offering my work to CPAN and one of the things
|> suggested on the PAUSE page is to solicit some public discussion, so
|> here goes...
|>
|> Is there anyone out there who would be interested in using a
|> crystallography module?
|>
|> Is there anyone out there who would be willing to test my work? (It
|> is pretty servicable at this time.)
|>
|> Is there anyone out there with some wisdom to offer regarding
|> scientific applications of perl and submission to CPAN?
|>
|> Thanks!!
|> Bruce
|>
|> --
|> Bruce Ravel ---------- bruce.ravel@nist.gov or ravel@phys.washington.edu
|> National Institute of Standards and Technology | Office: Room B356
|> Bldg 223, Room A215, Gaithersburg, MD 20899 USA | ph: 301-975-5759
|> http://feff.phys.washington.edu/~ravel | fax: 301-975-5334
--
Post away Bruce. i'd like to see what modules you use for the science apps.
--Brian
| Brian D. Schieber / SAIC General Sciences Corp.
| SeaWiFS Project / NASA Goddard Space Flight Center
| Code 970.2, Greenbelt, MD 20771
| schieb@seabass.gsfc.nasa.gov / (301) 286-1440
| http://seabass.gsfc.nasa.gov/~schieb/home_page.html
------------------------------
Date: Sun, 13 Dec 1998 23:23:23 GMT
From: mwatkins@3dmail.com (Mike Watkins)
Subject: Processing Incoming Mail?
Message-Id: <36744a7d.32791942@news.compuserve.com>
Hi there,
I am currently working on my newest project called the Automatic
E-Mail FollowUp System. You may view the admin control panel at
http://www.promotion4free.com/aefs/admin.cgi
I was wondering how can I have all incoming mail processed by a CGI
Script, without using .procmail or .forward. I only need to be able
to do this without having root access to my server.
What will happen, is when a new account is created, that account will
automatically receive an e-mail alias. Then whenever an e-mail is
sent to that alias, the CGI Script will process it, and add the
senders information to the appropriate account's address book.
I need this to be able to work on the majority of UNIX web servers.
So, I mean there can't be any required module which needs to be
installed, ect... Does anyone know any way to do this? If so, please
let me know. Could really use your help.
Thanks for your time,
Mike Watkins
mailto:mwatkins@3dmail.com
Web Site Replicator v2.0
http://www.promotion4free.com/scripts/
------------------------------
Date: Sun, 13 Dec 1998 20:34:31 +0100
From: "Nikolaus Filus" <NFilus@gmx.net>
Subject: script for choosing headers in mail (was: Re: script f|r newsheader Auswahl)
Message-Id: <75150d$jkl$1@carp.emsnet.de>
Allan M. Due schrieb in Nachricht <750gqt$583$0@206.165.165.138>...
> I just can't decide. Is this the driest joke I've heard in a long time?
A
>twisted example of recursion? A sincere, albeit inappropriately posted,
plea
>for help? I just can't tell.
Ups, sorry :-)))
My message was first written in german, but then i noticed it is an english
group and changed the body, but forgot to change the subject. Sorry :-)
Nikolaus
PS. and sorry for my bad english
------------------------------
Date: Sun, 13 Dec 1998 12:44:33 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Sorting problem: Is there a better way?
Message-Id: <MPG.10ddc70d34053191989955@nntp.hpl.hp.com>
[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...
> Tad McClellan wrote in message ...
> >Erik de Castro Lopo (please@see.sig) wrote:
> >
> >: I've got a list of items which are all of the form
> >: of one or more alpahbetic charaters followed by
> >: one or more digits and I need to sort them. The
> >: sorting should be done on the alphabetic part
> >: first. If there are two list items with the same
> >: alphabetic part they should be ordered on the basis
> >: of the size of the numeric part.
...
> > LarryR says he's tired, so we probably won't find out
> > which is faster... ;-)
Oh, yes you will, including one approach that hasn't been considered
yet. :-)
> 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)
#!/usr/local/bin/perl -w
use strict;
sub letters {
my @data;
foreach (1..100) {
push (@data,(join "", map {chr(97 +
rand(25))}(1..3)).(int(rand(1000))));
}
return \@data;
}
sub numbers {
my @data;
foreach (1..100) {
my $num = rand(25);
push (@data,(join "", map {chr(97 +
$num)}(1..3)).(int(rand(1000))));
}
return \@data;
}
sub _Default_sort{
# Schwartz Transform using default sort.
my $list = letters();
my @sorted =
map { substr $_, 1 + rindex $_, "\0" }
sort
map { /(\D*)(\d*)/; sprintf "\U$1\E%9d\0$_", $2 }
@$list;
# Note: The data have no percent signs, so substituting into the
# 'sprintf' format is safe. For the faint-hearted, this could be
# written as: sprintf "%s%9d\0%s", uc $1, $2, $_
# I doubt the benchmark result would change noticeably.
# Also, the right-adjusting parameter '9' depends on the maximum
# possible length of the digit string. This all works because the
# padding spaces sort lower than any alphanuerics, thus effectively
# terminate the alphabetical part of the sort. Some might prefer to
# insert another "\0" between the fields, and/or to zero-pad the digits.
$list = numbers();
@sorted =
map { substr $_, 1 + rindex $_, "\0" }
sort
map { /(\D*)(\d*)/; sprintf "\U$1\E%9d\0$_", $2 }
@$list;
}
sub _Swartz_Tran2{
# Schwartzian Transform (comments stripped for brevity)
my $list = letters();
my @sorted =
map { $_->[0] }
sort {
"\U$a->[1]" cmp "\U$b->[1]"
||
$a->[2] <=> $b->[2]
}
map { [$_, (split /(\d+)/)] }
@$list;
$list = numbers();
@sorted =
map { $_->[0] }
sort {
"\U$a->[1]" cmp "\U$b->[1]"
||
$a->[2] <=> $b->[2]
}
map { [$_, (split /(\d+)/)] }
@$list;
}
use Benchmark;
timethese(1000, {
'Default sort' => \&_Default_sort,
'Schwartzian Transform 2' => \&_Swartz_Tran2,
});
__END__
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.
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.
General comment:
A happy holiday season to everyone!
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sun, 13 Dec 1998 13:14:48 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Sorting problem: Is there a better way?
Message-Id: <MPG.10ddce1ecfa8a068989956@nntp.hpl.hp.com>
In article <MPG.10ddc70d34053191989955@nntp.hpl.hp.com> on Sun, 13 Dec
1998 12:44:33 -0800, Larry Rosler <lr@hpl.hp.com> says...
...
> map { /(\D*)(\d*)/; sprintf "\U$1\E%9d\0$_", $2 }
...
> # ... the right-adjusting parameter '9' depends on the maximum
> # possible length of the digit string.
Further thoughts on the above: As the conversion '%d' is used, '%10d'
would always suffice for a 32-bit perl implementation. But if the digit
string may be longer, it is better to use a conversion such as '%20s'.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 14 Dec 1998 10:41:39 +1100
From: Vincent Roy <roycych@hotmail.com>
Subject: Upload files CGI.pm and HTTP::Daemon
Message-Id: <367450B2.9F3C3D3E@hotmail.com>
Hi,
I am playing with the HTTP::Daemon module.
I successfully read Post and get parameters of a query, doing something
like:
new HTTP::Daemon ( LocalAddr =>$HOST, LocalPort => $PORT)
...
$c=$d->accept;
$r = $c->get_request;
...
$CGI::Q= new CGI $r->content;
Now when I try doing the same with multipart file uploads:
I did
...
$ENV{'REQUEST_METHOD'}=$r->method;
$ENV{'CONTENT_LENGTH'}=$r->content_length;
$ENV{'CONTENT_TYPE'}=$r->content_type;
...
open(FFF,">tmp.txt");
binmode FFF;
print FFF $r->content;
close(FFF);
close(STDIN);
open(STDIN,"<tmp.txt");
$query= new CGI;
...
Then when I do
$message =$query->param('file');
It says malformed multipart or simply doesnt return anything, depending
on the file.
Where have I been stupid ? Rewritting cgi is a pain...
Help most appreciated...
------------------------------
Date: 13 Dec 1998 12:00:05 GMT
From: tony@ns.cook.ml.org (Tony Cook)
Subject: Re: Using perl5 with Win95/dos command line.
Message-Id: <750a85$mgq$1@ns.cook.ml.org>
Randy Kobes (randy@theory.uwinnipeg.ca) wrote:
: On Wed, 2 Dec 1998 11:15:32 -0700 , Chris Hewell <CHewell@ile.com> wrote:
: [snip]
: > open (MAIL, "|mail chewell@ile.com");
: > print MAIL "bad news: $someone guessed $someguess\n";
: > close MAIL;
: Whenever you open something like this, it's always good to
: check the return value:
: open (...) or die "Can't open: $!\n"
: In this case it probably would have told you that the program
: 'mail' doesn't exist.
It won't actually. The fork is done before 'mail' is run, and the
open succeeds if the fork succeeds.
------------------------------
Date: Sun, 13 Dec 1998 20:07:44 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Writing Perl with Notepad
Message-Id: <36751e8b.1289858@news.skynet.be>
David Turley wrote:
>> In general: try using a text editor that allows you to save the file as
>> PC or Unix comaptible, as you wish.
>Isn't the choice of editors moot if you simply upload the file properly, ie.
>in ascii mode?
You are supposing the files move from CP (Windows) to Linux through FTP.
I am assuming that both systems can be local, that Linux and Windows
actually share a hard disk.
Bart.
------------------------------
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 4415
**************************************