[6506] in Perl-Users-Digest
Perl-Users Digest, Issue: 131 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 17 11:10:20 1997
Date: Mon, 17 Mar 97 08:00:22 -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 Mon, 17 Mar 1997 Volume: 8 Number: 131
Today's topics:
Re: [HELP] !@#$% sort subroutines... (Tad McClellan)
Re: [Q]Manipulating hash values <wkuhn@uconect.net>
Re: AntiSPAM is as bad as SPAM (was Can you help me wit <jc@hendel.mko.dec.com>
Bug in Mail::Send (John Goerzen)
continuation-passing and tail-recursion (Tony Bass)
Re: Convert DECUnix3.2 dbm to Solaris2.5.1 dbm (John Goerzen)
Re: Help needed with time and Perl <gooseman@mindspring.com>
Hip owls (was: Re: The fabulous pink camel (or red, if <tom@nospam.eiscat.no>
Re: How to spam - legitimately (Matthew Black)
Re: Install help for 5.003 on Solaris? SUCCESS (Jim Rudolf)
Re: Installing Modules under Macperl & Getting the best (Jim Easterbrook)
Re: Installing perl on Sun (brian d foy)
Re: keys from nested data structures -- is there an eas (Michael Constant)
Re: learning perl (Jay Flaherty)
Re: libwww 5.07 DESTROY.al <aas@bergen.sn.no>
Re: newbie question: how to pick a particular line in p <tom@nospam.eiscat.no>
NT 4.0 IIS Perl Problem with AOL <swinstan@quantime.co.uk>
Re: Perl frontend for MS Access (Andrew Gruskin)
Problems with MailTools package (John Goerzen)
Re: script to patch binaries (binpatch) (Robert L. Urban)
Splitting a multi line string <frax@goliat.publ.ica.se>
Transportable Agents <spurkis@engsoc.carleton.ca>
Re: What's a good Perl book? <merlyn@stonehenge.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 17 Mar 1997 08:48:05 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: [HELP] !@#$% sort subroutines...
Message-Id: <5jljg5.981.ln@localhost>
Vladimir Alexiev (vladimir@cs.ualberta.ca) wrote:
: In article <Pine.GSO.3.95q.970314192555.11801F-100000@linda.teleport.com> Tom Phoenix <rootbeer@teleport.com> writes:
: > Start with '0..$#_'. That's a list of the indices of the @_ array.
: Hey, shouldn't this be 0..$#_-1 ? We novices already have hard enough time
^^^^^^^^^^^^^^^^^^^^^^^^^^
Yes, if you want to ignore the last element in the array ;-)
: with perl :-)
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Mon, 17 Mar 1997 08:13:46 -0500
From: Bill Kuhn <wkuhn@uconect.net>
To: Darryl Caldwell <darrylc@eznet.com>
Subject: Re: [Q]Manipulating hash values
Message-Id: <332D438A.1332C434@uconect.net>
Not elegant, but gets the job done:
#!/usr/local/bin/perl -w
%hash = (99205,5,
80832,1,
99229,1,
83816,2,
99004,1,
99006,8) ;
# extract unique first three characters
for (keys(%hash)) {
if (!exists($sum{substr($_,0,3)})) {
$sum{substr($_,0,3)} = 0 ;
}
$sum{substr($_,0,3)} += $hash{$_} ;
}
# print them out
for (keys(%sum)) {
print $_,"-->",$sum{$_},"\n" ;
}
-Bill
--
Bill Kuhn
Chief Developer
Wired Markets, Inc.
http://www.buyersindex.com
------------------------------
Date: Mon, 17 Mar 1997 10:17:45 -0500
From: John M Chambers <jc@hendel.mko.dec.com>
Subject: Re: AntiSPAM is as bad as SPAM (was Can you help me with this script?)
Message-Id: <332D6099.3F54@hendel.mko.dec.com>
Devin Ben-Hur wrote:
>
> > Subject: Can you help me with this script?
> > From: BOB <somebody@somewhere.com>
> ^^^^^^^^^^^^^^^^^^^^^^
> > Message-ID: <5g4ndo$96e@qualcuno.nettuno.it>
>
> Hey, BOB!
> If you're going to partake of this public
> resource for free help and advise, please be a
> good citizen and use a real email address in your
> postings.
<SIGH>
Well, now; this isn't necessarily something that users have a whole
lotta choice over. If I were posting this followup (I hope it's a
followup ;-) from my home machine, I'd be able to edit the headers
and put a valid return address in the Reply-To: line. But here at
work, where I'm a contractor and have no say whatsoever in how the
network and usenet are managed, I seem to have little control over
the matter.
Why not? Well, to start with, I'm working behind a firewall. The
only tool that seems to be able to even see usenet here, much less
generate followups, is netscape. It did pop up this nice-looking
window, but there is no place visible that holds the headers, and
it seems pretty clear that I won't have any say in what they will
be. I can edit exactly two mail header lines, the Newsgroups: and
Subject: lines. I can pretty much guarantee that any email reply
to this message will bounce, and there just ain't a damned thing
I can do to fix it.
Well, maybe there is, but if so, it doesn't seem to be documented
anywhere. I've dug around in what passes for help in netscape's
online documentation, of course. Like most documentation, there's
little if any ability to grep for topics. If I know exactly what
they called the thing I'm looking for, maybe I can find it. But
if they provided a way to edit the news header lines, they called
it somthing that I can't guess. My suspicion is that they didn't
actually provide any such ability. They know better than an idiot
like me what the headers should look like, you know, and if I try
to edit them, I'll just screw them up, so why should they even let
me do such a thing?
More and more of the net is being loaded down with crufty tools
like this that do things wrong (like automatically generating email
addresses based on the assumption that user@host.domain will work
everywhere, even on the other side of a firewall), and don't give
the user any tools for fixing the failures even when we know how.
If I could only edit the Reply-To: line and insert a '%' and a
gateway's name, it'd work, but there just doesn't seem to be any
way to do such a thing.
Even from my home machine, I've seen more and more problems caused
by the "intelligent" sites on the network that say "Hey, I know a
better way to get back to you than that; let me rewrite your return
address so it'll work better ..." and proceed to generate a bogus
return address instead of the one that I supplied. Several friends
have shown me what they received, and we've spent some time trying
to finger the turkey that did the rewriting. Of course, usually
such information is only for our own satisfaction; the folks in
charge of the machine that did the rewriting are usually not willing
or able to do anything about it. (It's not *their* problem, after
all. ;-)
(To keep this perl-related; I might mention that on my home machine,
my little homegrown tcl email gui program invokes a whole lot of
perl scripts to do the actual work, including several that do a
pretty good job of correctly generating return addresses from all
sorts of bizarre email headers. But none of this is usable here,
because I don't know of any way to invoke them from netscape's news
windows. If anyone knows, you might post a pointer to wherever
the explanation might be hidden.)
With companies like Microsoft and <gag>IBM</gag> jumping onto the
net with both feet, things are gonna get a lot worse before they
get any better. We know what they think of their users' competence.
</SIGH>
[Now let's see if this actually *is* a followup ... ;-]
--
<a href="http://eddie.mit.edu/~jc">Home page</a> of
<a href="mailto:jc@eddie.mit.edu">John Chambers</a>.
Geek Code (V3.0):
GCC/CM/CS/E/IT/MU/O/PA/S d+ s+ a++ C++ P+++ L+++ E--- W++ N++ K+++ w O-
M V- PS++ PE- Y+ PGP+ t- 5 X- R tv-- b++ DI++++ D- G- e+++ h--- r+++
y++++
------------------------------
Date: 15 Mar 1997 03:55:27 GMT
From: jgoerzen@complete.org (John Goerzen)
Subject: Bug in Mail::Send
Message-Id: <slrn5ik7df.je7.jgoerzen@complete.org>
[ Courtesy copy to Tim Bruce ]
Hello,
Mail::Send refuses to put the Subject line into my message.
Even when I follow the example in the manpage precisely (only substituting a
variable for the string enclosed in apostrophes), it doesn't work. Instead
of adding a Subject: header, it inserts, as the first line of the message
*BODY*, the text:
~s Specified-subject-goes-here
Obviously not what it should do!
Thanks,
John Goerzen
--
John Goerzen | Running Debian GNU/Linux (www.debian.org)
Custom Programming |
jgoerzen@complete.org |
------------------------------
Date: 17 Mar 1997 09:10:38 -0000
From: aeb@calf.saltfarm.bt.co.uk (Tony Bass)
Subject: continuation-passing and tail-recursion
Message-Id: <5gj1qe$3fh@calf.saltfarm.bt.co.uk>
calf$ tailrec
6
6
6
6
6
6
6
6
686
21
calf$
#! /usr/local/bin/perl -w
# $Id: tailrec,v 1.11 1997/03/17 08:59:32 aeb Exp $
use strict;
# Some continuation-passing techniques are illustrated using the simple
# example of
# How to add up
# The conventional method of a for-loop is available in Perl,
sub sum1 {
my ($v) = @_;
my $sum = 0;
my $i;
for ($i=0; $i<@$v; $i++) { $sum += $$v[$i]; }
return $sum;
}
print sum1([1, 2, 3]), "\n";
# but foreach or grep offers a more concise and expressive style,
sub sum2 {
my ($v) = @_;
my $sum = 0;
grep { $sum += $_; } @$v;
return $sum;
}
print sum2([1, 2, 3]), "\n";
# However, this is committing all sorts of changes of state with its
# iterated assignment. It is not difficult to find a rendering that
# does not rely on such explicit state-changing,
sub sum3 {
my ($v) = @_;
return (not @$v) ? 0 : do {
my ($v0, @vrest) = @$v;
$v0 + &sum3([@vrest]);
};
}
print sum3([1, 2, 3]), "\n";
# but recursion in this form uses stack space proportional to the length
# of list to be added. The recursion can be put in tail position using
# the usual device of an accumulating parameter,
sub sum4a;
sub sum4 {
my ($v) = @_;
return sum4a 0, $v;
}
sub sum4a {
my ($acc, $v) = @_;
return (not @$v) ? $acc : do {
my ($v0, @vrest) = @$v;
sum4a $acc+$v0, [@vrest];
};
}
print sum4([1, 2, 3]), "\n";
# but perl still uses stack space proportional to list length.
# Actually, there is in any case considerable space usage for the vector
# tails, and also the vector itself, but this will be the same in all the
# examples, and is a minor technical irrelevance.
# A technique perhaps better suited to machines than people is available
# to improve matters. Instead of a value-returning subroutine we can use a
# subroutine applying an added continuation parameter to what it
# calculates,
sub sum5a;
sub sum5 {
my ($v, $c) = @_;
sum5a 0, $v, $c;
}
sub sum5a {
my ($acc, $v, $c) = @_;
(not @$v) ? &$c($acc) : do {
my ($v0, @vrest) = @$v;
sum5a $acc+$v0, [@vrest], $c;
};
}
sum5 [1, 2, 3], sub { print $_[0], "\n"; };
# This does not of itself help; but now, instead of a tail call we can
# return the function to be called to a common driver routine, so that the
# built-in stack nests just two subroutines deep, no matter how long the
# list of numbers.
sub driver {
my ($f, @args) = @_;
for (;;) {
($f, @args) = &$f(@args);
}
}
# which is the last assignment and loop we will ever have to write.
# We also need built-in printing and stopping continuations,
sub printit {
my ($x, $c, @rest) = @_;
print $x, "\n";
return $c, @rest;
}
sub stopit {
exit 0;
}
# And now a summing routine can execute in bounded space,
sub sum6a;
sub sum6 {
my ($v, $c, @rest) = @_;
return (\&sum6a, 0, $v, $c, @rest);
}
sub sum6a {
my ($acc, $v, $c, @rest) = @_;
return @$v ? (\&sum6a, $acc + $$v[0], [@$v[1..$#$v]], $c, @rest)
: ($c, $acc, @rest);
}
driver \&sum6, [1, 2, 3], \&printit,
# The technique is not confined to recursion in tail position, of course.
# Here is the continuation-passing equivalent of sum3, rendered with
# anonymous subroutines,
sub { $_[0], @_; }, sub {
my ($me, $v, $c, @rest) = @_;
return (not @$v) ? ($c, 0, @rest) : do {
my ($v0, @vrest) = @$v;
$me, $me, [@vrest], sub {
my ($y, $x, $c1, @rest1) = @_;
return $c1, $x+$y, @rest1;
}, $v0, $c, @rest;
};
}, [1, 2, 3], \&printit,
# where the built-in stack remains bounded two subroutines deep, but the
# recursion causes linear growth in the list of continuations remaining to
# be applied. The anonymous subroutine is made recursive by passing it to
# itself as first parameter.
# The inner sub could access $v0 directly instead of through parameter
# $y. That might be a more natural rendering, but would involve the
# lexical closure mechanism and so demand more of the underlying language.
# Note also the general overhead of continually recopying the list of
# future continuations. An alternative design with a reference wrapped
# somewhere around the area of @rest might be better in this respect,
# but would be more awkward for this presentation where comments are
# interleaved in a list of continuations.
# It now becomes clear that all the identifiers can be dispensed with,
# and likewise the do and returns, that are now no more than visual markers,
sub { $_[0], @_; }, sub {
(! @{$_[1]}) ? ($_[2], 0, @_[3..$#_]) :
$_[0], $_[0], [@{$_[1]}[1..$#{$_[1]}]], sub {
$_[2], $_[1]+$_[0], @_[3..$#_];
}, ${$_[1]}[0], $_[2], @_[3..$#_];
}, [1, 2, 3], \&printit,
# This is now just syntactic sugar for some Curry-Feys-Schoenfinkel
# combinators.
# Reverting to an optimised tail-recursion, and making the point at the
# same time that any calculation is amenable to continuation-passing
# treatment, we can take the inner product of two vectors,
sub {
my ($v, $w, $c, @rest) = @_;
return $c, [map { $$v[$_] * $$w[$_]; } 0..$#$v], @rest;
}, [34, 56], [7, 8],
# using a fully anonymised version of sum6, properly tail-recursive in
# bounded space,
sub { sub { $_[0], @_; }, sub { @{$_[2]}
? ($_[0], $_[0], $_[1] + ${$_[2]}[0], [@{$_[2]}[1..$#{$_[2]}]], @_[3..$#_])
: ($_[3], $_[1], @_[4..$#_]);
}, 0, @_;
}, \&printit,
# and we can calculate Fibonacci numbers
sub { sub { $_[0], @_; }, sub { $_[1]
? ($_[0], $_[0], $_[1] - 1, $_[2] + $_[3], $_[2], @_[4..$#_])
: ($_[4], $_[2], @_[5..$#_]);
}, $_[0], 1, 1, @_[1..$#_];
}, 6, \&printit,
# or anything else we really really want.
# It is a pity that "sub" is still needed, but apart from that it is
# all punctuation. Most satisfactory.
\&stopit;
Tony Bass
--
# Tony 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: 15 Mar 1997 00:43:54 GMT
From: jgoerzen@complete.org (John Goerzen)
Subject: Re: Convert DECUnix3.2 dbm to Solaris2.5.1 dbm
Message-Id: <slrn5ijs6a.h3f.jgoerzen@complete.org>
First a comment and then a suggestion.
You would do well you use GNU's dbm, which I believe is portable across
platforms (or at least platforms with the same "endianness").
A suggestion: write a simple network program that sends your database over
the network from your DEC to your Sun box. That way, you don't have to mess
with temporary files -- it will go directly into an output file.
On Tue, 11 Mar 1997 15:44:54 -0400, Victor Granic <vmg@novator.com> wrote:
>I have hundreds of dbm files on my AlphaStation running DECUnix3.2g
>that I need to use on a Solaris2.5.1 machine. Is there conversion
>software for this task before I go ahead and write all of the
>dbm files on the Alpha to text files and convert them back to
>dbm on the Solaris box? The royal pain with this task is that
>many of the dbm files are over 100 Mbytes and I'm severely running
>out of disk space.
>
>Help and suggestions welcome.
>Thank you,
>Victor Granic
--
John Goerzen | Running Debian GNU/Linux (www.debian.org)
Custom Programming |
jgoerzen@complete.org |
------------------------------
Date: Mon, 17 Mar 1997 07:16:40 -0800
From: Chris Burge <gooseman@mindspring.com>
Subject: Re: Help needed with time and Perl
Message-Id: <332D6058.23C0@mindspring.com>
Well the first time I didn't post the code bc the code is really bad.
I'm new to PERL. But here it is, you asked for it :). To explain it,
I'm trying to add a changing picture to my poalrity.shtml page that
already has a counter. It compiles right but the page has an error in
executing it.
Thanks,
Chris
#!/usr/bin/perl
alarm(600);
$HOME=(getpwnam("www03748"))[7];
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
if ($hour==7) {
open (FILE,">http://www.panoptica.com/polarity\.shtml");
print FILE "<html>/n";
print FILE "[<img src=\"http://www.panoptica.com/thinker1.jpg\">]\n";
close (FILE);
}
if ($hour==12) {
open (FILE,">http://www.panoptica.com/polarity\.shtml");
print FILE "<html>/n";
print FILE "[<img src=\"http://www.panoptica.com/thinker2.jpg\">]\n";
close (FILE);
}
if ($hour==18) {
open (FILE,">http://www.panoptica.com/polarity\.shtml");
print FILE "<html>/n";
print FILE "[<img src=\"http://www.panoptica.com/thinker3.jpg\">]\n";
close (FILE);
}
------------------------------
Date: 17 Mar 1997 13:16:41 +0100
From: Tom Grydeland <tom@nospam.eiscat.no>
Subject: Hip owls (was: Re: The fabulous pink camel (or red, if you prefer that), a review.)
Message-Id: <trwwr6iuhi.fsf_-_@palver.i-have-a-misconfigured-system-so-shoot-me>
jfriedl@tubby.nff.ncl.omron.co.jp (Jeffrey) writes:
> I wrote _Mastering Regular Expressions_ (O'Reilly) and discuss this issue
> at lengh.
I know you did (write the book), and I'm delighted that you do
(discuss /o vs. eval), and I'm going to buy one for my place of work
and one just for myself as soon as they arrive.
> * I'd like to think the book adds value to people using regular expressions
> in any language (including Perl), but would rather the book speak for
> itself than my mentioning it at every opportunity. I'm a computer geek,
> not a businessman, so I feel uncomfortable ``pushing'' my book.
It's been ordered days'n weeks ago, but hasn't arrived yet. Thanks
anyway.
Now just wait. Patience, patience ...
> Jeffrey Friedl <jfriedl@ora.com> Omron Corp, Nagaokakyo, Kyoto 617 Japan
--
//Tom Grydeland <Tom@nospam.eiscat.no> # delete 'nospam.' for valid address
The case of Randal Schwartz - http://www.lightlink.com/fors/
------------------------------
Date: 17 Mar 1997 15:43:50 GMT
From: black@csulb.edu (Matthew Black)
Subject: Re: How to spam - legitimately
Message-Id: <5gjorm$3nu@hatathli.csulb.edu>
In article <3322fa0d.470163687@news2.aimnet.com>, carroll@tjc.com says...
>
>On 03 Mar 1997 15:51:41 -0700, Randal Schwartz <merlyn@stonehenge.com>
>wrote:
>
>>>>>>> "Terry" == Terry Carroll <carroll@tjc.com> writes:
>>
>>Terry> The example you're trying to give here is not of the same type. "An
>>Terry> email" fills a gap in the English language. It provides a noun for a
>>Terry> concept that otherwise wouldn't have one.
>>
>>Funny, I find "some email" or "a piece of email" to be satisfactory.
>
>"Some email" doesn't refer to a particular piece of email. "a piece of
>email" is lengthy and unsatisfactory.
>
>>"an email" sounds strange. Very strange. To my native ears.
>
>And it sounds fine to my native ears, and to the native ears of a lot of
>other people. My point was that the "I've never heard a native speaker
>use it" slam is more probative of the slammer's limited circle than
>anything else.
Perhaps the author's friends have a limited understanding of American
style English grammar. By your argument, "irregardless" would be a
valid American English word.
============================================================================
matthew black | the opinions expressed herein are mine and
network & systems specialist | may not reflect those of my employer.
california state university |
network services SSA-180E | e-mail: black@csulb.edu
1250 bellflower boulevard | PGP fingerprint: 98 4E DF BE 49 A8 DF 99
long beach, ca 90840 | 6A 7A 1B F1 3E 50 E5 D2
=============================(c) 1996 by Matthew Black, all rights reserved=
------------------------------
Date: Mon, 17 Mar 1997 16:33:42 +0100
From: rudolf@metadesign.de (Jim Rudolf)
Subject: Re: Install help for 5.003 on Solaris? SUCCESS
Message-Id: <rudolf-1703971633420001@jim.metadesign.de>
Juergen Jaeschke wrote:
> Jim Rudolf wrote:
> >
> > My system: Sun Ultra, Solaris 2.5, gcc 2.5.6, perl 5.003
>
> I didn't encounter any problems with Sun Ultra, Solaris 2.5
> and gcc 2.7.2 -- maybe some of the probs rely in the old gcc:
> i'm not able to compile on linux with gcc 2.7.0.
Success! I downloaded 2.7.2 and the build went without a hitch.
This of course doesn't solve the Configure problem that generates
a list of thousands of signals, but I found another way around
that.
Thanks for the help,
Jim
------------------------------
Date: 17 Mar 1997 13:56:23 GMT
From: easter@rd.bbc.co.uk (Jim Easterbrook)
Subject: Re: Installing Modules under Macperl & Getting the best out of Makemaker
Message-Id: <5gjii7$lfe@bbcnews.rd.bbc.co.uk>
In article <schinder-1203971951030001@schinder.clark.net>, Paul J. Schinder (schinder@leprss.gsfc.nasa.gov) wrote:
# The way I look at it, as soon as I can I'll be installing Rhapsody on my
# Performa 6400. Then, if rumors are correct, I'll have, or be able to get,
# gcc and make. So this type of problem should disappear in less than a
# year. Until then, forget about MakeMaker (unless you have MPW) and the
# "standard" way of installing Perl modules.
Alternatively, buy MachTen CodeBuilder ($99) and have a unix environment
coexisting with MacOS now. You get gcc and make, plus perl and other
unix tools. I don't know about makemaker, but I expect you could build
it under CodeBuilder.
No connection etc., just another satisfied customer.
--
Jim Easterbrook
BBC Research & Development <http://www.bbc.co.uk/rd/>
*** All opinions are mine and might not be shared by the BBC ***
------------------------------
Date: Mon, 17 Mar 1997 08:42:50 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Installing perl on Sun
Message-Id: <comdog-1703970842500001@nntp.netcruiser>
In article <5gceeb$83e@kirchhoff2.ee>, rwhammel@mtu.edu (Hammelman) wrote:
> Secondly, I want to install Perl into a directory located under my user name,
> not the /usr/... that it tries to locate itself in. How do I go about this
> so that all other modules that I install will locate it under my user name?
did you run Configure (that came with the distribution)? it will ask
you where you would like to install perl.
> Third, a copy of Perl is located in the assumed /usr/... directory on my
> network. I want to install a few modules under my account. How do I force
> Perl scripts to find these modules under my account and not look for them
> in the assumed location?
Configure will also tell you how to solve that problem as well :)
--
brian d foy <URL:http://computerdog.com>
unsolicited commercial email is not appreciated
------------------------------
Date: 17 Mar 1997 04:34:00 -0800
From: mconst@soda.CSUA.Berkeley.EDU (Michael Constant)
Subject: Re: keys from nested data structures -- is there an easy way?
Message-Id: <5gjdno$t6h@soda.CSUA.Berkeley.EDU>
Hank Taylor <htaylor@mit.edu> wrote:
>i want to get the all sets of keys from a multi-dimensional hash. here's
>an example of the problem. the hash looks something like this:
>
> $hash{$outerkey}{$innerkey}.
>
>the set of outer keys is easy:
>
> @outer_keys = keys %hash;
>
>the *complete* set of inner keys is more problematic for me. the only
>way that i've been able to do it is to loop over all the outer keys and
>construct an array of unique keys for the keys in every sub-hash (eg.
>each of the %{$hash{$outerkey}} values).
These are really two separate problems: extracting a list of all the
inner keys, and then making sure each element of that list is unique.
Here's one way to extract the inner keys, with possible duplicates:
@inner_keys = map {keys %$_} values %hash;
Here's one way to remove the duplicates, by creating a temporary hash
whose keys are the elements of our array with duplicates:
@temporary{@inner_keys} = ();
@uniques = keys %temporary;
If you're looking for job security, you can do it all at once:
@uniques = keys %{{map %$_, values %hash}};
It may help to notice that the inner set of braces is constructing
an anonymous hash.
--
Michael Constant (mconst@soda.csua.berkeley.edu)
------------------------------
Date: 17 Mar 1997 13:29:33 GMT
From: fty@hickory.engr.utk.edu (Jay Flaherty)
Subject: Re: learning perl
Message-Id: <5gjgvt$i2v$1@gaia.ns.utk.edu>
Looks like you put zero effort searching the WWW. If you took 1 minute
and went to http://www.altavista.digital.com/ and searched for
"perl tutorial" you would have gotten 60,000+ hits in order of relevance.
Jay
sean (henriques@pobox.com) wrote:
: any suggestions on how a newbie can painlessly pickup the basics of
: perl?? Perhaps an online tutorial ??
:
: thanks in advance
:
: pls. respond to mailto://henriques@pobox.com
--
**********************************************
Jay Flaherty fty@hickory.engr.utk.edu
------visualize whirled peas------
**********************************************
------------------------------
Date: 17 Mar 1997 15:37:19 +0100
From: Gisle Aas <aas@bergen.sn.no>
Subject: Re: libwww 5.07 DESTROY.al
Message-Id: <hsp1ufuu8.fsf@bergen.sn.no>
Jeff Seifer <jeffs@pop3.silverplatter.com> writes:
> How come when I create a request object like:
>
> my $method = "POST";
> my $request = new HTTP::Request $method;
>
> I get the following error at the end of my program:
> Can't locate auto/LWP/UserAgent/DESTROY.al in @INC (in cleanup)
>
> DESTROY.al is NOT there - I just installed LWP 5.07 and got the same
> error. My program works fine, it's just an annoying message to get at
> the end of the script... Anyone know how to fix this???
Upgrade to a newer perl or add
sub LWP::UserAgent::DESTROY {}
to your script.
--
Gisle Aas <aas@sn.no>
------------------------------
Date: 17 Mar 1997 15:01:36 +0100
From: Tom Grydeland <tom@nospam.eiscat.no>
Subject: Re: newbie question: how to pick a particular line in perl5 (win32)
Message-Id: <tru3maipmn.fsf@palver.i-have-a-misconfigured-system-so-shoot-me>
Bill Kuhn <wkuhn@uconect.net> writes:
> By the way, in a unix shell I would use sed (stream editor) to get the
> 27th line as follows:
>
> sed -n '27,27p' file
What's wrong with
sed -n 27p file
??
> Bill Kuhn
--
//Tom Grydeland <Tom@nospam.eiscat.no> # delete 'nospam.' for valid address
The case of Randal Schwartz - http://www.lightlink.com/fors/
------------------------------
Date: 17 Mar 1997 14:48:14 GMT
From: "Sam Winstanley" <swinstan@quantime.co.uk>
Subject: NT 4.0 IIS Perl Problem with AOL
Message-Id: <01bc32e2$6c0fe530$52f352c1@sumo>
Has anybody heard of any problems executing Perl 5 script on IIS 2.0. We
have tried it and they work fine with all browsers except for AOL. Saying
this we have tried the same perl script on a UNIX Web Server and it worked
fine with the AOL Browser.
I would really appriciate any info at all. (preferably by email)
Many thanks
Sam Winstanley
mailto:swinstan@quantime.co.uk
------------------------------
Date: Mon, 17 Mar 1997 12:53:35 GMT
From: agruskin@melbpc.org.au (Andrew Gruskin)
Subject: Re: Perl frontend for MS Access
Message-Id: <332d3ddf.3940247@news.melbpc.org.au>
On 16 Mar 1997 16:04:53 -0500, clay@panix.com (Clay Irving) wrote:
>In <332C4300.B5B@best.com> Mark Peaslee <mpeaslee@best.com> writes:
>
>>Subject: Perl frontend for MSAccess
>
>>I'm new to PERL and have been given the task of creating a frontend for
>>a MS Access database. My thought is that this has already been done by
>>others and thought I would check and see if I could get some advice.
>>Does, anyone know if there is a program in perl already written for this
>>and if not, any advice on how I should go about creating one??? Any and
>>all advice is very welcomed.
>
>Looks like a job for the Win32::ODBC module -- Check Dave Roth's most
>excellent Web site at: http://www.roth.net/odbc/
>
An alternative to ODBC, which I must admit I haven't used, is OLE
Automation. See the man page 'oleauto'. By this method you use
Access as an OLE Automation Server.
Once you have created an Access object you can then operate with the
normal VBA methods and properties. This same facility is available
for creating a frontend to Excel.
Have fun! I was blown away when it worked.
------------------------------
Date: 15 Mar 1997 02:17:27 GMT
From: jgoerzen@complete.org (John Goerzen)
Subject: Problems with MailTools package
Message-Id: <slrn5ik1ln.i82.jgoerzen@complete.org>
According to the documentation, one should be able to do:
$maddr = Mail::Address->new(Mail::Address->parse($line));
but that doesn't work. Why?
--
John Goerzen | Running Debian GNU/Linux (www.debian.org)
Custom Programming |
jgoerzen@complete.org |
------------------------------
Date: 17 Mar 1997 14:44:11 GMT
From: urban@nasaxp.rto.dec.com (Robert L. Urban)
Subject: Re: script to patch binaries (binpatch)
Message-Id: <5gjlbr$hf@rtnews.rto.dec.com>
Here is a better version. If given an offset, it just seeks to it and
writes. By the way: it will never overwrite the original file unless
specifically asked to with the '-O' flag. Otherwise it writes to
"${infile}.out".
---------------------------- start ------------------------------
#!/usr/local/bin/perl
use FileHandle;
######################################################################
## script to patch strings in binary files. see binpatch -h
## for details.
##
## I recommend setting ts=4 in vi
##
######################################################################
$filepos = 0;
$done = 0;
$replcnt = 0;
$action = 'replace';
$scheme = 'search';
$chunksize = 4096;
$occurance = 1;
@args = ();
$READPOS = 0;
$WRITEPOS = 0;
$shellreturn = 1; # success
$overwrite = 0;
while ($_ = shift(@ARGV)) {
if (/^-f(.*)$/) {
$infile = $1 ? $1 : shift;
} elsif (/^-off=?(.*)$/) {
$offset = $1 ? $1 : shift;
$scheme = 'offset';
$shellreturn = 0;
} elsif (/^-o(.*)$/) {
$oldstring = $1 ? $1 : shift;
} elsif (/^-n(.*)$/) {
$newstring = $1 ? $1 : shift;
} elsif (/^-s(.*)$/) {
$oldstring = $1 ? $1 : shift;
$action = 'search';
} elsif (/^-d(.*)$/) {
$debug = $1 ? $1 : 1;
} elsif (/^-(\d+)$/) {
$occurance = $1;
} elsif (/^-all$/) {
$occurance = 0;
} elsif (/^-h/) {
Usage();
exit;
} elsif (/^-O/) {
$overwrite = 1;
} elsif (/^-/) {
print "What's that? [$_].\n";
exit -1;
} else {
push(@args,$_);
}
}
foreach (@args) {
if ($scheme eq 'offset') {
if (!$infile) {$infile = $_; next;}
if (!$newstring) { $newstring = $_; next;}
else {
print "What's that? [$_].\n";
exit -1;
}
} else {
if (!$infile) { $infile = $_; next;}
if (!$oldstring) { $oldstring = $_; next;}
if (!$newstring) { $newstring = $_; next;}
print "What's that? [$_].\n";
exit -1;
}
}
if ($debug) {
print "SCHEME: $scheme\n";
print "ACTION: $action\n";
print "INFILE: $infile\n";
print "OLDSTR: $oldstring\n";
print "NEWSTR: $newstring\n";
print "OFFSET: $offset\n";
}
if (!$infile) {
print "you must supply a file to patch\n";
Usage();
exit -1;
}
$outfile = $infile.'.out';
############################################################
# get the mode of the input file (minus the filetype) so I
# can set the mode on the output file, if necessary
# (dunno what this'l do on 32bit perl... probably shouldn't
# try to chmod at all...)
############################################################
$mode = (stat('/tmp/gp'))[2] & 07777;
if ($action eq 'replace') {
if ($scheme eq 'search') {
if (!$oldstring || !$newstring) {
print "you must supply old and new strings\n";
Usage();
exit -1;
}
if (length($oldstring) != length($newstring)) {
print "you must supply old and new strings\n";
Usage();
exit -1;
}
} else {
if (!$newstring) {
print "you must supply a new string\n";
exit -1;
}
}
}
if (($action eq 'search')&&!$oldstring) {
print "parameters are missing.\n";
Usage();
exit -1;
}
$strlen = length($oldstring) ? length($oldstring) : length($newstring);
if ($scheme eq 'offset') {
##############################################################
# open file, seek to offset, write
##############################################################
$size = -s $infile;
if ($offset+$strlen>$size) {
print "that would overwrite the end.\n";
exit -1;
}
if ($overwrite) {
$fh = new FileHandle "$infile", O_WRONLY;
} else {
if (system("cp $infile $outfile")) {
print "'cp $infile $outfile' failed.\n";
exit -1;
}
$fh = new FileHandle "$outfile", O_WRONLY;
}
binmode($fh); # for the Bill fans
seek($fh,$offset,0) || die "seek to offset $offset failed";
syswrite($fh,$newstring,$strlen) || die "syswrite";
close($fh);
exit 1;
}
open(IN,$infile) || die "open to read";
binmode(IN); # for the Bill fans
if ($action eq 'replace') {
print "writing to [".($overwrite ? $infile : $outfile)."]...\n";
open(OUT,">$outfile") || die "open to write";
binmode(OUT); # for the Bill fans
}
$carryover = '';
######################################################################
## the trick here is:
## in order to avoid missing a string that falls right on a chunk
## border, I use index() to test a chunk for the existence of the
## string to be replaced (or searced for). Then, as long as I'm
## still searching (i.e., I haven't found the string to be replaced),
## when I'm through with a chunk, I write the chunk MINUS a bit to
## the output file. The length of the bit not written is the length
## of the string to be found. Then I prefix that bit onto the next
## chunk read so and repeat my index() test. More or less:
##
## ======== [chunk]
## ======== [next chunk]
## overlap ^^ ======== [next chunk]
## overlap ^^
##
## This should work
## in both the single and multiple replacement cases, because in the
## multi-replacement case, assuming the string fell exactly in the bit
## that I hold over, the replacement will happen, then the bit will
## be prefixed, and the string will not match anymore (come to think
## of it, it wouldn't really matter either way).
## There is one anomaly, in the above-mentioned case, the SEARCH
## option would report an occurence of a string twice at the same
## offset. oh well.
######################################################################
TOP: while($chunklen = Read($chunk,$chunksize)) {
if (!$done) {
$chunk = $carryover.$chunk;
$chunklen += length($carryover);
$carryover = '';
##############################################################
## index doesn't seem to want to return the real offset within
## a scalar when the data is binary, so I must use
## substr to actually find the offset.
## however, index *does* seem to reliably *find* a substr in
## a binary scalar...
## *** your milage may vary ***
## (I'm using a real unix -- Digital UNIX :-))
##############################################################
if (index($chunk,$oldstring) != -1) {
#######################
## index() found string
#######################
$pos = 0;
while($pos < $chunklen) {
##########################################
## go through chunk, one byte at a time...
##########################################
$tmp = $chunklen - $pos;
####################################################
## for a single replacement, I don't have a problem,
## but for multiples, I must still check for the
## target string being chopped by a chunk boundary
####################################################
if (($tmp < $strlen)&&
(substr($chunk,$pos,$tmp) eq substr($oldstring,0,$tmp)))
{
###############################################
## match was cut by chunk boundary
## this _could_ backfire if I were
## searching for 'foobar' and the last 3 bytes
## of the current chunk were 'foo' and the next
## chunk continued with 'foofoofoofoofoofoo...'
## till the end but what the hell...
###############################################
if ($debug) {
print "grabbing a few more bytes...\n";
}
$len = Read($smallchunk,$strlen-$tmp);
if ($len != $strlen-$tmp) {
print "read failed ",$strlen-$tmp," bytes, dying\n";
exit -1;
}
$chunk .= $smallchunk;
$chunklen += $len;
redo;
}
if (substr($chunk,$pos,$strlen) eq $oldstring) {
print "found at ",$filepos+$pos;
$shellreturn = 0;
$replcnt++;
if (($action eq 'replace')&&
(($occurance == 0)||
($replcnt == $occurance)))
{
substr($chunk,$pos,$strlen) = $newstring;
print ", changed.";
if ($occurance) { # only one replacement
$done = 1;
print "\n";
next TOP;
}
}
print "\n";
$pos += $strlen;
} else {
$pos++; # no match? goto next byte
}
}
}
$carryover = substr($chunk,$chunklen - $strlen,$strlen);
$chunklen -= $strlen;
}
} continue {
if ($action eq 'replace') {
Write(substr($chunk,0,$chunklen),$chunklen) || die "syswrite";
}
$filepos += $chunklen;
}
if ($carryover) {
Write($carryover,length($carryover));
}
close(IN);
if ($action eq 'replace') {
close(OUT);
chmod $mode, $outfile;
if ($overwrite) {
rename($outfile,$infile);
}
}
if ($chunklen < 0) {
print "error with sysread\n";
}
exit $shellreturn;
##
## my version of sysread and syswrite
## so that I can track file offsets...
##
sub Read {
my($ret) = sysread(IN,$_[0],$_[1]);
if ($ret == -1) {
print "error reading input file\n";
exit -1;
}
if ($debug) {
print "%% read from offset $READPOS, SIZE=$ret\n";
}
$READPOS += $ret;
$ret;
}
sub Write {
my($ret) = syswrite(OUT,$_[0],$_[1]);
if ($ret == -1) {
print "error writing output file\n";
exit -1;
}
if ($debug) {
print "%% wrote at offset $WRITEPOS, SIZE=$ret\n";
}
$WRITEPOS += $ret;
$ret;
}
sub Usage {
print <<_EOF_;
Usage:
binpatch <filename> <OLD> <NEW> - Replace <OLD> with <NEW>
binpatch <filename> -off=<OFFSET> <STRING> - REPLACE at OFFSET
binpatch <filename> -s<STRING> - FIND OFFSET of STRING
OPTIONS:
-<N> - replace the Nth occurance of the string (0=all)
(default is 1st occurance only)
-all - replace all occurances
-f<filename> - explicitly specify filename
-off=<offset> - explicitly specify offset ('-off' is required)
-off <offset> - same
-s <string> - specify search string
-o <string> - explicitly specify <oldstring>
-n <string> - explicitly specify <newstring>
NOTE: when replacing a string, the lengths of OLD and NEW must be equal
_EOF_
}
---------------------------- end ------------------------------
--
Rob Urban
Digital Equipment GmbH
Freischuetzstr. 91
81927 Muenchen
Germany
------------------------------
Date: Mon, 17 Mar 1997 16:20:34 +0100
From: Fredrik Axtelius <frax@goliat.publ.ica.se>
Subject: Splitting a multi line string
Message-Id: <332D6117.61B5@goliat.publ.ica.se>
I got a multi line string that I need to
split in 2 pieces at the first word that ends with :
The string can look something like this
"dsad
asdas
asdas
asas
assqqs
someword:
asas
asas
asdasd
someotherword:
asas
asas"
I would like the split before someword:
someword is not always someword, it can be
a different word each time but always ends with a :
Any ideas??
/Fredrik
--
# Fredrik Axtelius frax@goliat.publ.ica.se #
# Disclaimer: Any opinions expressed above are my own, and do not #
# necessarily reflect the opinions of my employer. #
------------------------------
Date: Mon, 17 Mar 1997 10:33:51 -0500
From: Steve Purkis <spurkis@engsoc.carleton.ca>
Subject: Transportable Agents
Message-Id: <332D645F.F0E@engsoc.carleton.ca>
I'm curious: does anyone think that a transportable agent module (ie:
Agent.pm) is a good idea? The reason being I'm thinking about adopting
the project, and working for something that is actually useable; I'm
just wondering if it's worth my time.
I'd appreciate some feedback guys.
regards,
--Steve Purkis
Computer Engineering
spurkis@engsoc.carleton.ca
------------------------------
Date: 17 Mar 1997 07:04:58 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: slacker@dixonillinois.com
Subject: Re: What's a good Perl book?
Message-Id: <8c913msjg5.fsf@gadget.cscaper.com>
>>>>> "slacker" == slacker <slacker@dixonillinois.com> writes:
slacker> Then the llamma book although the first chapter is a doosy until you
slacker> figure out what it's referring to in the later chapters.
Good. That means you read it right, and that chapter wasn't meant for
*you* until later.
Some people want concepts first, some people want structure first,
some people want examples first. The second half of chapter one is
for people that want examples first. If you're not that way, then
it'll seem odd to you.
I unconciously put in a mix of the three types of stuff throughout the
book, based on my experiences since 1978 of being a technical writer.
However, I *did* favor "concept first" because that's the way I think,
and just writing that chapter one was against my grain (although I'm
very glad now that my friend Steve suggested^W demanded it). Now that
I'm aware of the different learning styles, I'm consciously altering
the way I create new writings and training materials to incorporate
that.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 533 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
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@ora.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: 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 131
*************************************