[6931] in Perl-Users-Digest
Perl-Users Digest, Issue: 556 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 2 11:07:32 1997
Date: Mon, 2 Jun 97 08:00:43 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 2 Jun 1997 Volume: 8 Number: 556
Today's topics:
Re: $ENV{PWD} versus `pwd' <dorman@s3i.com>
Re: 2-way communication with unix command (Michael J Assels)
5.004 problem with Hashes <mystery@itis.com>
Re: 5.004 problem with Hashes (Lack Mr G M)
Re: 5.004 problem with Hashes <seay@absyss.fr>
ANNOUNCE: Net::DNS 0.09 (Michael Fuhr)
ANNOUNCE: TeX::DVI, Hyphen and Font::TFM in version 0.0 (Honza Pazdziora)
ANNOUNCE: Text::Boilerplate-0.08 <senelson@negentropy.com>
Re: any editor for perl?--any editor written in Perl? (John Klassa)
Re: any editor for perl? (David Combs)
Re: Any plans for perl plug-ins? (Mark Nielsen)
Re: books <dean@tbone.biol.sc.edu>
BSD::Resource 1.06 <jhi@alpha.hut.fi>
Re: Can I perl script download a HTML page??? <dean@tbone.biol.sc.edu>
re: Command line args <mcnichol@mcs.net>
Re: data structure question <friedman@uci.edu>
example perl v. caml performance (Tony Bass)
Re: filter out uids below 100 <keys@babylon5fan.com>
Re: Idiom for list summation? <dean@tbone.biol.sc.edu>
Re: Linux issues with 5.004. <c.evans@clear.net.nz>
LOG base 10 operator <miker@maverick.facil.uconn.edu>
Re: MacPerl and filetypes (Chris Nandor)
Re: Mailto Perl script for NT <petri.backstrom@icl.fi>
Re: More PERL questions (Chipmunk)
Re: Need vacation program in Perl! <piet@cs.ruu.nl>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 02 Jun 1997 09:40:55 -0400
From: Clark Dorman <dorman@s3i.com>
Subject: Re: $ENV{PWD} versus `pwd'
Message-Id: <dvi3x3yxk.fsf@s3i.com>
Clark Dorman <dorman@s3i.com> writes:
[snip]
> Grrr....this would seem to be "wrong" to me. If I change the
> directory that we are "in" using chdir, the environment has changed,
> and when I look at the ENV hash, it should change as well.
Thanks for all those that responded. chdir in the script does not
change the environment variables.
> This brings up the next question: how do I determine which directory
> I'm working in _without_ doing system calls?
The short answer: you don't. The slightly longer answer of course is
that I should use the proper module:
use Cwd;
and then use Cwd's handy-dandy "cwd" function. A quick look at Cwd.pm
indicates that the cwd function does a `pwd` and chops it. (Aside:
why chop and not chomp?) So, a system call is done anyway. getcwd is
also available and it uses opendirs, stats, and readdirs.
--
Clark Dorman "Evolution is cleverer than you are."
http://cns-web.bu.edu/pub/dorman/D.html -Francis Crick
------------------------------
Date: 2 Jun 1997 12:25:39 GMT
From: mjassels@cs.concordia.ca (Michael J Assels)
Subject: Re: 2-way communication with unix command
Message-Id: <5mue43$42c$1@newsflash.concordia.ca>
In article <8cpvu6tjm3.fsf@gadget.cscaper.com>,
Randal Schwartz <merlyn@stonehenge.com> wrote:
>
>But it'd be really funny if this same "management" *requires* you to
>respond to any CERT security notice by installing the required
>patches: there have been at least a few CERT-ifiable notices against
>4.036, 5.001, 5.002 and 5.003. The safest version of Perl is *now*
>5.004.
Does this mean 5.004 is *now* a production release? The Perl home page
tells me that "Version 5.004 of perl has now entered beta." Perhaps I
should stop reading comp.lang.perl.announce and subscribe to perl5-porters
for current info?
>print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
I still look forward to the day when Randal will finally be legally
disencumbered (ouch!) so that he can go back to writing *real* JAPHs.
Michael
--
$@='@'^'@';$_='!'&~'"';$/='"'&~'!';$^='$'&~'!';$,='('&~'!';$#='$'&'"';$~='?'^
'/';$;='@';$_="".($_|$^|$#|$;).($_|$/|$#|$;).($,|$#|$;).($_|$/|$^|$,|$#|$;).($#
).($/|$#).($_|$^|$,|$;).($_|$,|$#|$;).($_|$/|$#|$;).($,|$#|$;).($_|$#|$;).($_|
$^|$#|$;).($^|$,|$#|$;).($/|$#).($/|$^|$,|$~|$#).($/|$^|$#).($/|$~|$#);`$_`
------------------------------
Date: Mon, 02 Jun 1997 08:22:33 -0400
From: Prince Mystery <mystery@itis.com>
Subject: 5.004 problem with Hashes
Message-Id: <3392BB09.FF6@itis.com>
I'm getting an error that I didn't used to get when the system was on
the previous version of perl (5.003):
Odd number of elements in hash list at...
Over the line:
%final = {};
Now that I look back in the documentation, I see that while nothing
appears to say that this is right or wrong, it does manage to work.
This error appears to be a warning, rather than a call to die.
Because I've got a number of processes running on a crontab, I get a 500
line message twice a day with just this error on it. Can someone help
me before my inbox explodes? Thanks.
Myst
------------------------------
Date: Mon, 02 Jun 1997 14:03:39 BST
From: gml4410@ggr.co.uk (Lack Mr G M)
Subject: Re: 5.004 problem with Hashes
Message-Id: <1997Jun2.140339@ukwit01>
In article <3392BB09.FF6@itis.com>, Prince Mystery <mystery@itis.com> writes:
|> I'm getting an error that I didn't used to get when the system was on
|> the previous version of perl (5.003):
|>
|> Odd number of elements in hash list at...
|>
|> Over the line:
|>
|> %final = {};
undef %final;
or
%final = ();
--
----------- Gordon Lack ----------------- gml4410@ggr.co.uk ------------
The contents of this message *may* reflect my personal opinion. They are
*not* intended to reflect those of my employer, or anyone else.
------------------------------
Date: Mon, 02 Jun 1997 16:14:02 +0200
From: Douglas Seay <seay@absyss.fr>
To: Prince Mystery <mystery@itis.com>
Subject: Re: 5.004 problem with Hashes
Message-Id: <3392D52A.1B59EAAD@absyss.fr>
[posted and mailed]
Prince Mystery wrote:
>
> I'm getting an error that I didn't used to get when the system was on
> the previous version of perl (5.003):
>
> Odd number of elements in hash list at...
>
> Over the line:
>
> %final = {};
shouldn't that be
%final = (); # parens, not braces
> Now that I look back in the documentation, I see that while nothing
> appears to say that this is right or wrong, it does manage to work.
> This error appears to be a warning, rather than a call to die.
I always use "-w" and "use strict" so as to avoid this little things.
Going in over my head so be prepared for errors: with assignments to
hashes, the hash is treated like a @list, so there is no error checking
for this kind of thing. %final was a list of one element, namely a
reference to an anonymous hash. When you tried to use this as a %hash,
it saw an odd number of elements in the list and went AWOL.
- doug
------------------------------
Date: 2 Jun 1997 14:39:20 GMT
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: ANNOUNCE: Net::DNS 0.09
Message-Id: <5muluo$fhl$1@nadine.teleport.com>
Net::DNS is a module for doing DNS queries in Perl. Version 0.09
should be making its way around CPAN; you can also download it from:
http://www.dimensional.com/~mfuhr/perldns/
Here's the relevant excerpt from the Changes file:
*** 0.09 29 May 1997
Net::DNS is now being developed under Perl 5.004. I'll try to keep
it compatible with earlier versions of Perl, at least for a while.
Got rid of an eval in RR.pm and replaced unpack with substr in
several places. After all other changes in this version, a simple
benchmark of a zone transfer showed the new code using about 25%
less CPU time than the old code. Mileage will vary based on the
program, of course, and programmers probably shouldn't expect to
see much improvement.
Debugging is now printed during packet parsing instead of after
the entire packet has been parsed. This can be useful for examining
corrupt packets.
Added support for NAPTR RRs. Thanks to Ryan Moats for contributing
the necessary code.
Wrote demo/axfr to demonstrate how to save a zone transfer to a
disk file and read it back later. Requires the Storable module.
BUG FIX: If no "nameserver" lines are found in the resolver config
files, queries should go to the nameserver running on the local
host. Previous behavior left the nameserver list empty, causing
all queries to fail with the error "no nameservers". Problem noted
by Dr Eberhard W Lisse.
BUG FIX: Added checks for missing data in packets - this should
eliminate the "@ outside of string" errors that can happen if the
packet is corrupt. In these cases, queries will return undef and an
explanation of the error (e.g., "answer section incomplete") will be
present in $res->errorstring. Problem noted by Martin Lichtin and
Stephen Hebditch.
--
Michael Fuhr
http://www.dimensional.com/~mfuhr/
------------------------------
Date: 2 Jun 1997 14:41:52 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: ANNOUNCE: TeX::DVI, Hyphen and Font::TFM in version 0.04
Message-Id: <5mum3g$fj9$1@nadine.teleport.com>
Keywords: Perl TeX DVI TFM module hyphenation
Hallo,
I have uploaded to PAUSE new versions of my three TeX related Perl modules:
TeX::DVI, TeX::Hyphen and Font::TFM. They are of version 0.04 now. They
should appear on CPAN soon. URL http://www.fi.muni.cz/~adelton/perl/
is the primary location.
The modules help in accessing TeX input and output data format from
Perl. TeX::DVI has low level interface for writting out the .dvi
(DeVice Independent) file; TeX::Hyphen allows hyphenation of words
according to TeX's hyphenation patterns; and Font::TFM provides methods
to read metric information from .tfm files. Readme's are included with
the modules, so I would only include here part of my email answer that I
have written today:
---
> After a moderate amount of hacking, I thought I'd better ask you
> personally : at first sight, the DVI module helps transforming a ASCII
> string into a DVI file ... is that it ?
Well, not really, it's not a filter like mpage (that makes
PostScript). It's merely a low level interface to those functions that
appear in the DVI file. So the user needs to know what he is doing,
what commands are needed. In this, the dvitype program (and its
source) is good start.
So you for example write
my $dvi = new TeX::DVI "texput.dvi";
$dvi->preamble();
$dvi->begin_page();
and this will create a file texput.dvi and put preamble of the DVI
format and the mark of the begin of new page into it. And so on. I am
not sure if anybody would appreciate interface at higher level.
As for the Font::TFM module, it reads the info from a .tfm file about
the metrics of a font and the methods allow to get the info.
The two modules can cooperate in producing good output, because they
do ligature and kerning expansion authomatically. But they also give
user methods for any DVI command.
---
Enjoy!
--Honza Pazdziora
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
I can take or leave it if I please
Have you done your DES today? --> http:/www.des.sollentuna.se/
------------------------------
Date: 2 Jun 1997 14:39:47 GMT
From: Steve Nelson <senelson@negentropy.com>
Subject: ANNOUNCE: Text::Boilerplate-0.08
Message-Id: <5mulvj$fi0$1@nadine.teleport.com>
Greetings all...
This posting announces the alpha release of Text::Boilerplate, a Perl
module allowing scripts to format output using special template files.
Boilerplates let you separate what a script does from what its output
looks like, using a simple mark-up language which is easy for
non-programmers to learn.
Generally, I use Text::Boilerplate to create CGI scripts which output
NTML, although it can be used for almost any formatting task. Instead
of hard-coding the HTML code into the script, I place the HTML in a
separate file, and replace the items that the script should interpolate
with Boilerplate tags. Keeping the HTML separate from the script itself
makes maintaining scripts far easier.
Text::Boilerplate is similar to preprocessing modules such as
Text::Template and Text::Vpp. It offers the following additional
features:
* Designers use an HTML-like markup system to create boilerplate files.
* Repeating blocks-- designers can specify that a block of text should
be repeated for every element of a list, making HTML table and list
creation far easier.
* Efficiency: Boilerplates are translated into Perl code on
initialization, speeding up the process of filling them in.
Text::Boilerplate is still in alpha; use it at your own risk, and expect
changes to future releases. It's available from:
http://www.slip.net/~senelson/
This site contains HTMLized documentation and the latest version of the
Text::Boilerplate module. I'd very much appreciate any comments as to
how to improve the module or the documentation; please send such to
senelson@negentropy.com.
------------------------------
Date: 2 Jun 1997 13:45:52 GMT
From: klassa@gumby.ivc.com (John Klassa)
Subject: Re: any editor for perl?--any editor written in Perl?
Message-Id: <5muiqg$odu$2@vortex.ivc.com>
On 30 May 1997 14:31:13 -0700, Randal Schwartz <merlyn@stonehenge.com> wrote:
->It's been in the CPAN for quite a long time...
-> http://www.perl.com/CPAN/src/misc/nvi.tar.gz
Now what we _really_ need is an emacs clone that uses perl as its extension
language... I wonder if John Davis can be convinced to put a new spin on
Jed. :-)
--
John Klassa (W) klassa@ivc.com (H) klassa@ipass.net
<>< http://www.ivc.com/~klassa http://www.ipass.net/~klassa
(pgp fingerprint: 3C EE B4 02 40 76 DA 80 F1 96 90 FD 7A 1D 7D 53)
------------------------------
Date: Mon, 2 Jun 1997 13:21:54 GMT
From: dkcombs@netcom.com (David Combs)
Subject: Re: any editor for perl?
Message-Id: <dkcombsEB5H4I.6G4@netcom.com>
In article <338AF477.FE11738D@hkstar.com>, ccm <cat33@iname.com> wrote:
>I am a new user in Perl.
>I found that those .pl files edited under Win95/Dos Editor will not work
>properly.
>But if I edit them in the unix shell with pico, they works fine.
>is out there any editor which workable with perl under Win95/Dos
>Environment?
Having read all the responses to this question, and
all the suggested editors, I saw only one that mentioned
emacs -- and that's all it did -- mention it.
Does no one reading this newsgroup use Emacs??????
Well, if not, you sure don't know what you are missing!
------------------------------
Date: 2 Jun 1997 08:12:24 -0400
From: men2@auto.med.ohio-state.edu (Mark Nielsen)
Subject: Re: Any plans for perl plug-ins?
Message-Id: <5mudb8$bci@auto.med.ohio-state.edu>
>I think you're looking for the Penguin project. Pengiun can do all of the
>main things that Java can do, except that it works on more kinds of
>systems, it uses Perl, and it fails to send a stream of money to Sun. :-)
>You'll find it on CPAN. Hope this helps!
Yes thanks! I found it.
However, I was wondering about something, although I love Linux, our
public computers are NT 4.0 using Netscape communicator.
Anyways, I don't see how to set it up so that I can get Netscape
to execute penguin code. I thought I read all the documents that
came with penguin, but I didn't see anything that explained how to do it.
I did read that a plugin has not been developed yet, but since it hasn't
how do I get Netscape to execute the code whether it is on Linux or NT?
I have Perl 5 for NT.
Thanks for the info and any comments appreciated!
Mark
--
---------------------------------------------------------------------------
Mark Nielsen men2@auto.med.ohio-state.edu or gytres+@osu.edu
Systems Specialist
The Ohio State University
------------------------------
Date: 29 May 1997 12:35:45 -0400
From: Dean Pentcheff <dean@tbone.biol.sc.edu>
Subject: Re: books
Message-Id: <m1zpteb5i6.fsf@nauplius.psc.sc.edu>
Pierre Merle <pmerle@corp.sun.com> writes:
> I think this as already been asked ...
> I writing html/perl pages and I need a book.
> Which is better ? I don't need a book with cdrom
> and tons of unusefull PC oriented stuff. I need a book to explain perl
> AND html in details. To complement brilliant net resources I've found.
> Maybe two separates books are better, I use perl by exemple by
> Ellie Quipley and HTML for fun and profit.
> First is good but only perl, second is old and too simple.
> What about Oreilly books ?
O'Reilly consistently produces excellent books. For Perl, you'll want
to check Learning Perl and Programming Perl. Learning Perl is just
about to come out with a second edition (I'm not sure exactly when),
and Programming Perl is already on its second edition.
O'Reilly also has several books that address HTML (as I recall). I
haven't seen them, so I can't directly recommend them, but I'm willing
to bet that they're good. One nice thing about the O'Reilly WWW site
(<URL:http://www.ora.com>) is that they generally give the table of
contents and sometimes a sample chapter of their books, so you can get
a good idea if it will cover the things in which you're interested.
-Dean
--
N. Dean Pentcheff <pentcheff@acm.org> WWW: http://tbone.biol.sc.edu/~dean/
Biological Sciences, Univ. of South Carolina, Columbia SC 29208 (803-777-3936)
PGP ID=768/22A1A015 Keyprint=2D 53 87 53 72 4A F2 83 A0 BF CB C0 D1 0E 76 C0
Get PGP keys and information with the command: "finger dean@tbone.biol.sc.edu"
------------------------------
Date: 2 Jun 1997 14:42:15 GMT
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
Subject: BSD::Resource 1.06
Message-Id: <5mum47$fji$1@nadine.teleport.com>
The BSD::Resource release 1.06 is available as
http://www.perl.com/CPAN/authors/id/JHI/BSD-Resource-1.06.tar.gz
The release 1.06 is just the release 1.05_02 renamed. The release
1.05_02 again was the second bugfix release for the release 1.05.
In short, all the reported bugs in the release 1.05 have been fixed.
No new functionality is introduced by the release 1.06.
The Perl extension BSD::Resource provides interface to the BSD
process resource and priority API: getrusage() getrlimit()
setrlimit() getpriority() getpriority().
--
$jhi++; # http://www.iki.fi/~jhi/
# There is this special biologist word we use for 'stable'.
# It is 'dead'. -- Jack Cohen
------------------------------
Date: 29 May 1997 13:18:14 -0400
From: Dean Pentcheff <dean@tbone.biol.sc.edu>
Subject: Re: Can I perl script download a HTML page???
Message-Id: <m1vi42b3jd.fsf@nauplius.psc.sc.edu>
fl_aggie@hotmail.com (I R A Aggie) writes:
> In article <338d78e9.4032899@news.tiac.net>, smithj@statenislandonline.com
> (Johnathan Mark Smith) wrote:
> + Can I perl script download a HTML page???
> Yes.
> + Please Email me back
> No.
> James
To expand briefly on that: the annoyance comes from your failure to
seek anywhere for information. A cursory search in any WWW search
site would have yielded: http://www.perl.com . From that site,
you'd have found the Perl Modules list. In that you'd have found
oodles of WWW-related modules. Particularly LWP::Simple.
-Dean
--
N. Dean Pentcheff <pentcheff@acm.org> WWW: http://tbone.biol.sc.edu/~dean/
Biological Sciences, Univ. of South Carolina, Columbia SC 29208 (803-777-3936)
PGP ID=768/22A1A015 Keyprint=2D 53 87 53 72 4A F2 83 A0 BF CB C0 D1 0E 76 C0
Get PGP keys and information with the command: "finger dean@tbone.biol.sc.edu"
------------------------------
Date: Mon, 02 Jun 1997 10:08:22 -0500
From: Greg McNichol <mcnichol@mcs.net>
Subject: re: Command line args
Message-Id: <3392E1E6.323E9792@mcs.net>
Hello all!
I am a Perl "newbie" currently working my way through the SAM's book:
_Teach Yourself Perl 5 in 21 Days_. Up until this point I have written
DOS batch files to enable end users basic file copy capabilities from
outside the Windows interface. I would like to translate some of these
files to Perl scripts. So, for example, if I want a user to be able to
copy a file called test.txt and one called test.doc (both of which
reside in different directories on the hard drive) from a local to a
network directory just by typing test -- can I do this in Perl?
Thanks much. Please respond via e-mail.
------------------------------
Date: 2 Jun 1997 14:24:02 GMT
From: "Eric D. Friedman" <friedman@uci.edu>
Subject: Re: data structure question
Message-Id: <5mul22$g3m@news.service.uci.edu>
In article <5mtpbk$ei4$1@paladin.american.edu>,
Jon Nathan <jn0729a@cage.cas.american.edu> wrote:
>i'm trying to write a script that will be a simple quote server. it will read
>in a quote and the source of the quote from a textfile formatted as such:
>
>1.Take me out to the ballgame.
>1.Some song
>2.Whatever
>2.Joe Smith
>
>etc. the format for the file is not written in stone, however it seemed good to
>me at the time. once it reads in all the quotes from the file, it should print
>one out at random, along with the source. because i would eventually like to
>play with the source too, i want to keep it in a seperate variable. that said,
>this is my (ugly) code so far:
I would lose the numbers and just keep count as you read through the file.
You know that quote n has source n+1, so this is not too challenging.
>-----start code-------
>
>open(QUOTES, "//usr//people//nathanj//quotes");
What's with the double //? Why do you interpolate variables in a string
which has none? where is your fallback if open() fails? or die...
>while ($quote=<QUOTES>){
in 5.004 you can do
while (my $quote = <QUOTES>)
in earlier perls, you can do
my $quote;
while ($quote = <QUOTES>)
> chop($quote); #get a line from the file
what about chomp?
> $num=/$(\d+\.)/; #digit(s) followed by a period
You can't be running with -w and use strict, or you'd surely get an
error for not declaring the scope of $num. You should really read
the fine manual, which repeatedly stresses the impportance of those
tw tools.
That said, I don't see how you'd get $num from this equation (not that
it is not a pattern match, which is probably ntot clear to you because
you seem to have this thing against whitespace.
> $quote=~s/\1//; #take the digit(s) and period out
Now why would you do TWO pattern matches wher eonly one is needed?
Do this instead:
# untested!
my $file = '/path/to/file';
open FH, $file or die "Can't read $file: $!";
my @results;
while (my $quote = <FH>)
{
chomp $quote;
chomp (my $source = <FH>);
push @results, [ $quote, $source ] ;
}
now get a random number between 0 and $#results, grab that element of the
array, dereference it and move on.
--
Eric D. Friedman
friedman@uci.edu
------------------------------
Date: 2 Jun 1997 12:59:30 +0100
From: aeb@brains.cartoon.bt.co.uk (Tony Bass)
Subject: example perl v. caml performance
Message-Id: <5mucj2$aqp$1@brains.cartoon.bt.co.uk>
Actual comparisons of real problems implemented in more than one way are
rare enough that I felt this example, admittedly small, might be of
general interest.
The requirement was for an algorithm iterating over a potentially large
graph. First experiments in perl (version 5.001 Unofficial patchlevel
1m) tended to be heavy on memory, so I optimised the first real perl
implementation for least memory usage, using a handful of pack of
integer to represent the graph,
calf$ vmonmem -t5 netmin -v z.net >z.perl
vmonmem host calf
vmonmem date Thu May 22 09:47:25 BST 1997
vmonmem command netmin -v z.net
vmonmem 0.598 Mbyte
netmin: 10K nodes read
vmonmem 1.828 Mbyte
netmin: 20K nodes read
vmonmem 1.828 Mbyte
netmin: 30K nodes read
vmonmem 1.953 Mbyte
netmin: initialised D 3
vmonmem 2.078 Mbyte
netmin: refined D 5
...
vmonmem 2.078 Mbyte
netmin: refined D 29
vmonmem 2.078 Mbyte
netmin: refined D 29
vmonmem 2.328 Mbyte
netmin: checked for duplicate edges
vmonmem date Thu May 22 09:48:52 BST 1997
vmonmem real 1:26.0 user 1:22.1 sys 0.4
calf$
testing on an artificial example with a local "vmonmem -t5" reporting
memory usage every 5 seconds and then Unix times at the end. Most of
the time is spent in the iterative routine that increases D until
convergence. The source code for this routine is
sub RefineD {
my %hash = (); # key on D followed by all edge Ds
my $oldD = $D;
$nextD = 0;
my $n;
Intvec($D, 0) = $nextD++;
for ($n=1; $n<$numNodes; $n++) {
my $em1 = Intvec($nextEdge, $n) - 1;
my $key = ""; # Intvec
my $q;
for ($q=Intvec($numNext, $n); $q>0; $q--) {
Intvec($key, $q) = Intvec($oldD, Intvec($nextNode, $em1+$q));
}
Intvec($key, 0) = Intvec($oldD, $n);
substr($key, 4) = &IntSet(substr($key, 4)) if ($omask & 1);
# hash-convert $key to new integer D
my $eset = $hash{$key};
if (!defined $eset) {
$eset = $nextD++;
$hash{$key} = $eset;
}
Intvec($D, $n) = $eset;
}
}
This gave a fairly satisfactory stand-alone tool. However, further
requirements arose to have internal data structures and iteration in a
form that would easily interleave with other processing, and I wrote a
more modular functional-style perl version, using a single array of
pack of integer to represent the graph,
calf$ vmonmem netlink -v z.net >z.link
vmonmem host calf
vmonmem date Thu May 22 09:03:42 BST 1997
vmonmem command netlink -v z.net
vmonmem 0.605 Mbyte
vmonmem 2.500 Mbyte
vmonmem 10.082 Mbyte
vmonmem 10.207 Mbyte
...
vmonmem 10.207 Mbyte
vmonmem 10.207 Mbyte
netlink: main 29 nodes
vmonmem date Thu May 22 09:28:18 BST 1997
vmonmem real 24:21.0 user 22:44.4 sys 3.3
calf$
sub refineD {
my ($self, $D) = @_;
my $n = $self->{GRAPH};
my %hash = ();
my $dn = 0;
return (
[map {
my ($w, @e) = unpack 'I*', @$n[$_];
my $key = pack 'I*', $$D[$_], @$D[@e];
($hash{$key} ||= ++$dn) - 1;
} 0..$#$n],
$dn);
}
In general the performance is not as bad as this worst-case artificial
example might suggest, and we got another useful tool out of this.
Then a colleague downloaded caml-light 0.73, and I took the opportunity
to try a first draft feasibility study, using a single vector of pair
of something with vector of int to represent the graph,
calf$ vmonmem -t5 mlink <z.net >z.ml
vmonmem host calf
vmonmem date Thu May 22 09:45:00 BST 1997
vmonmem command mlink
vmonmem 0.113 Mbyte
vmonmem 2.922 Mbyte
vmonmem 5.426 Mbyte
vmonmem 5.426 Mbyte
vmonmem 6.434 Mbyte
dn 3
dn 5
vmonmem 7.195 Mbyte
dn 7
dn 9
dn 11
vmonmem 7.957 Mbyte
dn 13
dn 15
dn 17
vmonmem 8.211 Mbyte
dn 19
dn 21
dn 23
vmonmem 8.719 Mbyte
dn 25
dn 27
dn 29
vmonmem date Thu May 22 09:45:47 BST 1997
vmonmem real 45.0 user 43.7 sys 0.3
calf$
let refineD g (d, _) = let n = vect_length g
and hash = hashtbl__new 1023
and dn = ref 0
in let v = vect_of_fun
n
(fun i -> let {Info=info; Edges=edges} = g .(i) in
let key = (d .(i)) :: (map (vect_item d) edges) in
try hashtbl__find hash key
with Not_found -> let x = !dn in (hashtbl__add hash key x; incr dn; x))
in (v, !dn);;
Faster than the perl implementations, concise source code, fairly heavy
memory usage as in default perl usage.
As with the perl versions, I was able to reduce memory usage by more
detailed programming, using a handful of int vect to represent the
graph,
calf$ make run
vmonmem -t5 mlink <z.net
vmonmem host calf
vmonmem date Mon Jun 2 09:07:44 BST 1997
vmonmem command mlink
vmonmem 0.578 Mbyte
vnet: 10000 lines
vmonmem 1.086 Mbyte
vnet: 20000 lines
vmonmem 1.086 Mbyte
vnet: 30000 lines
vnet: D 5
vmonmem 1.594 Mbyte
vnet: D 7
vnet: D 9
vmonmem 2.102 Mbyte
vnet: D 11
vnet: D 13
vnet: D 15
vmonmem 2.355 Mbyte
vnet: D 17
vnet: D 19
vmonmem 2.355 Mbyte
vnet: D 21
vnet: D 23
vnet: D 25
vmonmem 2.609 Mbyte
vnet: D 27
vnet: D 29
vmonmem 2.609 Mbyte
vnet: D 29
vmonmem date Mon Jun 2 09:08:30 BST 1997
vmonmem real 42.0 user 41.5 sys 0.1
calf$
(Or with subscript checking turned off about 30 secs). The source code
of the iteration routine is still fairly concise,
and refineD = fun olddn d -> let hash = hashtbl__new hinit
and v = make_vect N 0 in
let rec dlist = fun p q y -> if p=q then y
else dlist (p+1) q ((vect_item d (vect_item edge p)) :: y)
and iter = fun i dn ->
if i < N then let p = vect_item ix i and q = vect_item ix (i+1) in
let key = ((vect_item d i), (dlist p q [])) in
iter
(i+1)
(try (vect_assign v i (hashtbl__find hash key); dn)
with Not_found -> hashtbl__add hash key dn; vect_assign v i dn; (dn+1))
else dn
in let dn = iter 0 0 in
fprintf stderr "vnet: D %d\n" dn;
flush stderr;
if dn = olddn then compress dn v
else refineD dn v
As usual with comparisons, it is very difficult to get a level
playing-field. The main qualification that occurs to me is that the
built-in caml vects used in this implementation would set a limit of
about 4 million nodes maximum graph size (whereas the perl limit is
available memory). I can imagine ways round the caml limit, at some
cost in time performance.
But my general feeling from this spot-sample is that, other things being
equal (which they aren't), for a medium-scale application of this sort
(whatever "of this sort" might mean) a caml-light 0.73 rendering would
have shorter source code and better performance than a perl 5.001
rendering.
Tony Bass
--
# A E Bass Tel: (01473) 645305
# MLB 3/19, BT Laboratories e-mail: aeb@saltfarm.bt.co.uk
# Martlesham Heath, Ipswich, Suffolk, IP5 7RE DO NOT e-mail to From: line
# Opinions are my own
------------------------------
Date: Sun, 01 Jun 1997 12:19:47 -0600
From: Keys <keys@babylon5fan.com>
Subject: Re: filter out uids below 100
Message-Id: <3391BD43.43D9@babylon5fan.com>
Here's what someone suggested via email, and it works well, for anybody
else who may have been following this thread... Thanks to all for the
help.
while(($login,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell)=getpwent)
{
next if $uid <=100; # skip administrative accounts.
($name,$office,$phone)=split(/,/,$gcos);
$username{$login}=$name;
}
> You just want to skip users whose uid is below 100, right? Take
> a look at the perlsyn manual page and read about loop control and
> decision-making.
>
> --
> Michael Fuhr
> http://www.dimensional.com/~mfuhr/
------------------------------
Date: 29 May 1997 13:05:45 -0400
From: Dean Pentcheff <dean@tbone.biol.sc.edu>
Subject: Re: Idiom for list summation?
Message-Id: <m1yb8yb446.fsf@nauplius.psc.sc.edu>
Joe Klein <jklein@alerts.co.il> writes:
> On 29 May 1997, Tim Smith wrote:
> > In article <5mj3d3$et7$1@marina.cinenet.net>,
> > Craig Berry <cberry@cinenet.net> wrote:
> > >I have the need to take a list of numbers and determine their sum. I can
> > >easily to this with code like this:
...
#!/usr/local/bin/perl
use Benchmark;
@short = ( 1 .. 5 );
@long = ( 1 .. 5000 );
timethese(100000, {
'short-for' , '$s=0; for (@short) {$s+=$_;}',
'short-map' , '$s=0; map{$s+=$_} @short; ',
'short-eval', '$s=eval join " + ", @short; ',
});
timethese(200, {
'long-for' , '$s=0; for (@long) {$s+=$_;}',
'long-map' , '$s=0; map{$s+=$_} @long; ',
'long-eval' , '$s=eval join " + ", @long; ',
});
Benchmark: timing 100000 iterations of short-eval, short-for, short-map...
short-eval: 29 secs (29.29 usr 0.02 sys = 29.31 cpu)
short-for: 2 secs ( 1.79 usr 0.00 sys = 1.79 cpu)
short-map: 3 secs ( 2.31 usr 0.00 sys = 2.31 cpu)
Benchmark: timing 200 iterations of long-eval, long-for, long-map...
long-eval: 33 secs (32.74 usr 0.04 sys = 32.78 cpu)
long-for: 2 secs ( 1.97 usr 0.00 sys = 1.97 cpu)
long-map: 4 secs ( 4.24 usr 0.00 sys = 4.24 cpu)
[Platform: Linux 2.0.27 on a 200 MHz Pentium Pro, Perl 5.004]
Conclusion: Despite their nifty appearance, alternatives to
"for/foreach" lose in efficiency (whether working on long or short
arrays). Corollary: avoid "eval" like the plague unless you really
need dynamically generated code.
-Dean
--
N. Dean Pentcheff <pentcheff@acm.org> WWW: http://tbone.biol.sc.edu/~dean/
Biological Sciences, Univ. of South Carolina, Columbia SC 29208 (803-777-3936)
PGP ID=768/22A1A015 Keyprint=2D 53 87 53 72 4A F2 83 A0 BF CB C0 D1 0E 76 C0
Get PGP keys and information with the command: "finger dean@tbone.biol.sc.edu"
------------------------------
Date: 02 Jun 1997 00:25:51 +1200
From: Carey Evans <c.evans@clear.net.nz>
Subject: Re: Linux issues with 5.004.
Message-Id: <87u3jia4s0.fsf@psyche.evansnet>
rachel@virago.org.au (Rachel Polanskis) writes:
[snip]
> Works fine anyway, and that 12kb perl binary plus the nice shared
> library is a wonderful thing, since my system runs many perl processes
> simultaneously...
Actually, all modern OS's will share the code of a program using the
same method as they do for shared libraries[1]. So using a shared
library will just make Perl marginally slower. Of course, it _is_
neat to have a 12K /usr/bin/perl, and it's also good for the Perl
compiler.
> I love it!
No problems with this.
[1] Some more than others: OS/400 seems to call shared libraries "service
programs". (Have you ever seen a setuid shared library?!)
--
Carey Evans <*> c.evans@clear.net.nz
"Lies, damn lies, and computer documentation."
------------------------------
Date: 2 Jun 1997 12:36:43 GMT
From: "Michael J. Rocchetti" <miker@maverick.facil.uconn.edu>
Subject: LOG base 10 operator
Message-Id: <01bc6f51$08fa8080$1e716389@miker.maverick.facil.uconn.edu>
Does anyone know how to take the log base 10 of a number using PERL?
miker
------------------------------
Date: Mon, 02 Jun 1997 08:56:14 -0400
From: pudge@pobox.com (Chris Nandor)
Subject: Re: MacPerl and filetypes
Message-Id: <pudge-ya02408000R0206970856140001@news.idt.net>
In article <3391F19F.4AEF@geenite.demon.co.uk>, Matthew Knight
<matt@geenite.demon.co.uk> wrote:
#i want to create a droplet application in perl which will set the
#filetype and creator when i drop a file on the application.
>From the "Macintosh specific features" help file:
MacPerl::SetFileInfo(CREATOR,TYPE,FILE...)
Changes the file types and creators of the file(s).
Examples:
MacPerl::SetFileInfo("MPS ", "TEXT", yin, yang);
Turn yin and yang into MPW text files
--
Chris Nandor pudge@pobox.com http://pudge.net/
%PGPKey=('B76E72AD',[1024,'08 24 09 0B CE 73 CA 10 1F F7 7F 13 81 80 B6 B6'])
#=============================================================================
Friday, I was in a bookstore and I started talking to a French looking girl.
She was a bilingual illiterate -- she couldn't read in two different
languages.
--Steven Wright
#=============================================================================
------------------------------
Date: Fri, 30 May 1997 11:46:25 +0200
From: Petri Backstrom <petri.backstrom@icl.fi>
Subject: Re: Mailto Perl script for NT
Message-Id: <338EA1F1.7B06@icl.fi>
Jeff Garner wrote:
>
> I'm looking for a Perl Mailto script for NT. Are there any mailto
> scripts for NT. I know about them for Unix boxes but haven't found a
> ported one for NT.
>
> Thanks in advance for the help
> Jeff
Then you haven't looked hard enough. If you know about such
scripts, you must have bumped into formmail.pl, and if you
go and look at "Matt's Script Archive", where formmail.pl
originates, you'd also find ports to Win95/WinNT using
BLAT and other tools.
I leave finding BLAT and Matt's Script Archive as an
excercices to you. Use, e.g., http://altavista.digital.com,
or http://www.dejanews.com to search this newsgroup (where
information about both have been posted before).
regards,
...petri.backstrom@icl.fi
ICL Data Oy
Finland
------------------------------
Date: 2 Jun 1997 06:56:01 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: More PERL questions
Message-Id: <5mtqq1$vfb$2@dartvax.dartmouth.edu>
In article <33903845.4F580F6@teleport.com>
Doyle Tracy <doyle@teleport.com> writes:
> I'm working on a reseaerch project on PERL (which I
> know nothing about)
That's why it's called a research project.
Perhaps you should try doing some research.
Chipmunk
------------------------------
Date: 02 Jun 1997 11:32:58 +0200
From: Piet van Oostrum <piet@cs.ruu.nl>
Subject: Re: Need vacation program in Perl!
Message-Id: <wz206l1h9x.fsf@kemmel.cs.ruu.nl>
>>>>> Mongkol Horburapa <q13382@bang.cig.mot.com> (MH) writes:
MH> I provided the correct email, though.
MH> It might be the problem on my company's gateway.
MH> Could You try sending to q13382@bkkhp1.bang.cig.mot.com ?
That doesn't work either.
--
Piet van Oostrum <piet@cs.ruu.nl>
URL: http://www.cs.ruu.nl/~piet [PGP]
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 556
*************************************