[17813] in Perl-Users-Digest
Perl-Users Digest, Issue: 5233 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 4 17:36:29 2001
Date: Thu, 4 Jan 2001 14:36:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <978647765-v9-i5233@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 4 Jan 2001 Volume: 9 Number: 5233
Today's topics:
Re: Making a program run repeatedly (Richard Zilavec)
Re: Making a program run repeatedly <ssomneb@my-deja.com>
Re: Making a program run repeatedly <mischief@velma.motion.net>
Re: Making a program run repeatedly <joe+usenet@sunstarsys.com>
Re: Making a program run repeatedly (Gregory Spath)
matching info from parallel arrays? <seppy@chartermi.net>
Re: matching info from parallel arrays? (Tad McClellan)
Re: matching info from parallel arrays? nobull@mail.com
Matching-Operator question <SiStie@nuclear-network.de>
Re: Matching-Operator question <jhelman@wsb.com>
Re: Matching-Operator question (Tad McClellan)
Re: Matching-Operator question <SiStie@nuclear-network.de>
Re: Matching-Operator question <SiStie@nuclear-network.de>
Memoize internal functions? Gordon.Haverland@agric.gov.ab.ca
Re: Memoize internal functions? (Anno Siegel)
Re: Memoize internal functions? (Abigail)
min, max (was: Re: Is Perl dying?) <kevin@vaildc.net>
Re: min, max (was: Re: Is Perl dying?) (Randal L. Schwartz)
Re: min, max (was: Re: Is Perl dying?) <joe+usenet@sunstarsys.com>
Re: mod_perl install problem <webqueen@my-deja.com>
more info on map function <nospam@nospam.com>
Re: more info on map function <uri@sysarch.com>
Re: more info on map function (Tad McClellan)
Re: more info on map function <uri@sysarch.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 29 Dec 2000 14:23:43 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: Re: Making a program run repeatedly
Message-Id: <3a4c9df9.73389756@news.tcn.net>
On Fri, 29 Dec 2000 07:46:43 GMT, John Galt <ssomneb@my-deja.com>
wrote:
>I've written a perl script that I want my linux machine to run
You should consider posting this message in one of the comp.os.linux.*
groups, it would be more appropriate.
>automatically every 5 minutes (or any length of time). I'm pretty new
man crontab
--
Richard Zilavec
rzilavec@tcn.net
------------------------------
Date: Fri, 29 Dec 2000 19:38:01 GMT
From: John Galt <ssomneb@my-deja.com>
Subject: Re: Making a program run repeatedly
Message-Id: <92ip6o$r90$1@nnrp1.deja.com>
I got it to work, thanks!
Sorry for being off-topic.
One more question (I couldn't find it in any of the perl tutorials I've
read): How do I append (might be the wrong term) a scalar? Like if I
wanted to combine "a" and "b" to make "ab"? $c=$a+$b didn't work, and
neither did $c eq $a+$b Have I overlooked something simple?
Again, thanks a lot! It's appreciated.
In article <3a4c9df9.73389756@news.tcn.net>,
rzilavec@tcn.net wrote:
> On Fri, 29 Dec 2000 07:46:43 GMT, John Galt <ssomneb@my-deja.com>
> wrote:
>
> >I've written a perl script that I want my linux machine to run
>
> You should consider posting this message in one of the comp.os.linux.*
> groups, it would be more appropriate.
>
> >automatically every 5 minutes (or any length of time). I'm pretty
new
>
> man crontab
>
> --
> Richard Zilavec
> rzilavec@tcn.net
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 29 Dec 2000 20:19:52 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Making a program run repeatedly
Message-Id: <t4psf86ljobgd4@corp.supernews.com>
John Galt <ssomneb@my-deja.com> wrote:
> I got it to work, thanks!
> Sorry for being off-topic.
> One more question (I couldn't find it in any of the perl tutorials I've
> read): How do I append (might be the wrong term) a scalar? Like if I
> wanted to combine "a" and "b" to make "ab"? $c=$a+$b didn't work, and
> neither did $c eq $a+$b Have I overlooked something simple?
> Again, thanks a lot! It's appreciated.
Many languages do what you are expecting. They do this by overloading
the common numerical operators to also work with strings, which are
a different data type.
Since Perl uses scalars without much regard for whether they are
numbers or strings until they are used, it is difficult to judge
how the mathematical operators should be overloaded to also work
with strings.
The solution is to not overload the operators to work with strings.
There are therefore operators specific to strings for comparison
and concatenation.
op meaning
---------------------------
. concatenate
.= concatenate in place
gt greater than
ge greater than or equal
lt less than
le less than or equal
eq equality test
ne inverse equality test
cmp string comparison
The comparisons are locale-sensitive if a locale is defined.
You can see 'perldoc perlop' for more information.
Chris
--
Christopher E. Stith
Even in the worst of times, there is always someone who's never had it better.
Even in the best of times, there is always someone who's never had it worse.
------------------------------
Date: 29 Dec 2000 15:20:13 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Making a program run repeatedly
Message-Id: <m3lmsz6kua.fsf@mumonkan.sunstarsys.com>
[please put your replies after the quoted material. thanks.]
John Galt <ssomneb@my-deja.com> writes:
> One more question (I couldn't find it in any of the perl tutorials I've
> read): How do I append (might be the wrong term) a scalar? Like if I
> wanted to combine "a" and "b" to make "ab"? $c=$a+$b didn't work, and
> neither did $c eq $a+$b Have I overlooked something simple?
> Again, thanks a lot! It's appreciated.
% man perlop
$ab = "a" . "b" ; # Binary "." concatenates strings
--
Joe Schaefer
------------------------------
Date: Mon, 01 Jan 2001 01:31:38 -0000
From: gspath@freefall.homeip.net (Gregory Spath)
Subject: Re: Making a program run repeatedly
Message-Id: <slrn94vndm.446.gspath@freefall.homeip.net>
you could make the program a daemon and let it sleep 5 minutes between doing
its thing, or probably better, run the program using cron. The former will use
memory constantly.
In <92hfh3$rdj$1@nnrp1.deja.com>, John Galt (ssomneb@my-deja.com) wrote:
>I've written a perl script that I want my linux machine to run
>automatically every 5 minutes (or any length of time). I'm pretty new
>to this; any ideas on how to do that? Is it a linux thing or a perl
>thing?
>Thanks!
>
>
>Sent via Deja.com
>http://www.deja.com/
--
Gregory Spath
gspath@freefall.homeip.net http://freefall.homeip.net/
SCHeckler on IRC ----------> http://freefall.homeip.net/javairc/
Team YBR ------------------> http://www.yellowbreechesracing.org/
------------------------------
Date: Fri, 29 Dec 2000 09:24:06 -0500
From: "Brian E. Seppanen" <seppy@chartermi.net>
Subject: matching info from parallel arrays?
Message-Id: <3A4C9E86.6C511FCC@chartermi.net>
I'm new to perl, and I need to write something that will take
information gathered from a report and match it to the actual email
address of the user. Here's what I have.
Each night I grab an export of popids, and emailaddress. I read this
file into an array that I call @ids. Later in my script I assign the
modified output of repquota to my @quotainfo array.
@quotainfo=`/usr/sbin/repquota /dev/sda6 | grep -v "^root | grep -v
"^other" |
grep -v "^ Block limits File
limits"|
grep -v "^User used soft hard grace used soft
hard grace"|
tr -d - | tr -d + `;
foreach $entry(@quotainfo) {
($username,$bused,$bsq,$bhq,$bgrace,$fused,$fsq,$fhq)=split(/\s+/,$entry,8);
I'm having trouble seeing the structure to how I can take two arrays and
get the proper id.
I should mention the structures of the two arrays:
ids consists of two comma seperated fields. The first is the users
COMPLETE pop ID, the second is the actual email address.
@quotainfo as you can see has eight different variables. One thing to
note is the first variable is a shortened version of the pop ID. It's
at max 10 characters.
Another question can you assign three or more variables to a hash?
Any ideas would be greatly appreciated.
TIA
Brian Seppanen
Charter Communications
Regional Data Center 906-228-4226 ext 23
Marquette, MI seppy@chartermi.net
------------------------------
Date: Fri, 29 Dec 2000 08:44:37 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: matching info from parallel arrays?
Message-Id: <slrn94p5a5.jsm.tadmc@magna.metronet.com>
Brian E. Seppanen <seppy@chartermi.net> wrote:
>I'm new to perl, and I need to write something that will take
>information gathered from a report and match it to the actual email
>address of the user. Here's what I have.
>
>Each night I grab an export of popids, and emailaddress. I read this
>file into an array that I call @ids.
^^^^^
You want to form "associations" between POPids and email addresses?
A hash (formerly known as an "associative array") would be a good
data structure for that.
[ snip @quotainfo filled with filtered output from 'repquota' program ]
>foreach $entry(@quotainfo) {
>
>($username,$bused,$bsq,$bhq,$bgrace,$fused,$fsq,$fhq)=split(/\s+/,$entry,8);
>
>I'm having trouble seeing the structure to how I can take two arrays and
>get the proper id.
>
>I should mention the structures of the two arrays:
>ids consists of two comma seperated fields. The first is the users
>COMPLETE pop ID, the second is the actual email address.
You could (should?) use a hash instead of an array:
my %ids;
$ids{$billid} = $billaddr;
>@quotainfo as you can see has eight different variables. One thing to
>note is the first variable is a shortened version of the pop ID. It's
>at max 10 characters.
So you need to correlate the POPids in "@ids" to the truncated
ids in $username?
( that will fail horribly if the usernames are not unique in
the first 10 characters...
)
In that case, you can truncate the hash key, then see if
$username is a key in the hash:
$ids{ substr $billid, 0, 10 } = $billaddr;
...
if ( exists $ids{$username} ) # found a "match"
>Another question can you assign three or more variables to a hash?
Yes, you can have multilevel data structures in Perl. You need to
know Perl's "references" to get that done. See:
perldoc perlreftut
perldoc perlref
perldoc perllol
perldoc perldsc
>Any ideas would be greatly appreciated.
Rethink your data structures before coding.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 29 Dec 2000 17:22:47 +0000
From: nobull@mail.com
Subject: Re: matching info from parallel arrays?
Message-Id: <u97l4j5ehk.fsf@wcl-l.bham.ac.uk>
"Brian E. Seppanen" <seppy@chartermi.net> writes:
> I'm new to perl, and I need to write something that will take
> information gathered from a report and match it to the actual email
> address of the user.
So what you are looking for is like an SQL join across two Perl arrays.
> I'm having trouble seeing the structure to how I can take two arrays and
> get the proper id.
That's 'cos they should be hashes, keyed on the id field. Actually
for n joined arrays only n-1 need to be keyed on the id field.
> I should mention the structures of the two arrays:
Yes, that would help :-)
> ids consists of two comma seperated fields. The first is the users
> COMPLETE pop ID, the second is the actual email address.
> @quotainfo as you can see has eight different variables. One thing to
> note is the first variable is a shortened version of the pop ID. It's
> at max 10 characters.
# Produce a hash containing email addresses keyed by tuncated
# ID
my %email;
for (@ids) {
my ($id,$email) = split ',';
$email{ substr($id,0,10) } = $email;
}
# Traverse the @quotainfo array
for (@quotainfo) {
my ($username,$bused,$bsq,$bhq,$bgrace,$fused,$fsq,$fhq)=split;
my $email = $email{$username};
# Do stuff
}
> Another question can you assign three or more variables to a hash?
That's a very odd question. I think you are actually asking can a
a single entry in a hash be multivalued. No but it can be a reference
to arbitrarily complex structure.
See: perldoc perldsc
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Sat, 30 Dec 2000 14:00:39 +0100
From: Simon Stiefel <SiStie@nuclear-network.de>
Subject: Matching-Operator question
Message-Id: <Pine.LNX.4.31.0012301351160.1536-100000@server.stiefel.priv>
Hi,
I just wrote that:
--- snip ---
$icq =3D "xxx";
while ($icq !~ m/[0-9]*/)
{
print "ICQ-UIN [num.] [<ENTER> for none] ? ";
$icq =3D <STDIN>;
chomp ($icq);
}
--- snap ---
How must I modify the matching-operator to accept <ENTER>?
Thank you!
Mit freundlichen Gr=FC=DFen, .~. Open Minds.
with best regards /V\ Open Sources.
// \\ Open Future!
Simon Stiefel /( )\_ I N U X
^ ~ ^
--=20
|Simon Stiefel | Zwerbachstrasse 17 | 72555 Metzingen-Glems | Germany |
|SimonStiefel@nuclear-network.de | http://www.nuclear-network.de |
|ICQ#: 20196644 | phone: +49(0)7123/379070 | fax: +49(0)179/335990106 |
|Tux#: 114751 | PingoS - Linux-User helfen Schulen | Powered by LiNUX |
------------------------------
Date: Sat, 30 Dec 2000 14:01:22 GMT
From: Jeff Helman <jhelman@wsb.com>
Subject: Re: Matching-Operator question
Message-Id: <clqr4tctqnrrte1a2b6g9bh3ueiu1ts346@4ax.com>
On Sat, 30 Dec 2000 14:00:39 +0100, Simon Stiefel
<SiStie@nuclear-network.de> wrote:
>Hi,
>
>I just wrote that:
>
>--- snip ---
>$icq = "xxx";
>while ($icq !~ m/[0-9]*/)
>{
> print "ICQ-UIN [num.] [<ENTER> for none] ? ";
> $icq = <STDIN>;
> chomp ($icq);
>}
>--- snap ---
As you are aware, this doesn't do what you expect. You are telling
the interpreter to execute your loop while $icq does not contain 0 or
more digits. Since your original value matches this criteria, your
loop never executes.
If I remember correctly (and correct me if I'm wrong), ICQ ids are all
numeric (i.e. no letters or other characters). In that case, the
following will work.
$icq = "xxx";
until ($icq =~ /^\d*$/) {
print "ICQ-UIN [num.] [<ENTER> for none] ? ";
$icq = <STDIN>;
chomp ($icq);
}
This tells perl to loop until $icq contains zero or more digits and
nothing else (since I used the ^ and $ pattern anchors to indicate the
beginning and end of the string).
A couple of notes. First, note that in regular expressions, \d is
equivalent to [0-9], but is more readable. Second, if you are using
the forward slash as your delimiter in a regex, you can exclude the
leading m, since m is used to specify a different delimiter.
Hope this helps,
JH
------------------------------
Date: Sat, 30 Dec 2000 07:51:08 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Matching-Operator question
Message-Id: <slrn94rmhs.36l.tadmc@magna.metronet.com>
Simon Stiefel <SiStie@nuclear-network.de> wrote:
>$icq = "xxx";
>while ($icq !~ m/[0-9]*/)
>{
> print "ICQ-UIN [num.] [<ENTER> for none] ? ";
> $icq = <STDIN>;
> chomp ($icq);
>}
>How must I modify the matching-operator to accept <ENTER>?
You have a bigger problem than that.
Your loop body can *never* execute.
m/[0-9]*/ matches the empty string. Every string contains the
empty string. That pattern matches all possible strings!
So the m/[0-9]* part is _always_ true.
So ($icq !~ m/[0-9]*) can never be true.
So your loop body can never execute.
Be careful writing patterns where everything is optional:
while ($icq !~ m/[0-9]+/) # this _might_ be what you want, but we
# cannot provide you a correct pattern
# because you have not said what you want...
(do you really want to exit the loop when 'foo1bar' is entered?)
To exit the loop when the user hits enter, put this following the chomp():
last unless length $icq; # zero length
or
last if $icq eq ""; # empty string
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 31 Dec 2000 16:55:30 +0100
From: Simon Stiefel <SiStie@nuclear-network.de>
Subject: Re: Matching-Operator question
Message-Id: <Pine.LNX.4.31.0012311654180.891-100000@server.stiefel.priv>
On Sat, 30 Dec 2000, Jeff Helman wrote:
> If I remember correctly (and correct me if I'm wrong), ICQ ids are all
> numeric (i.e. no letters or other characters). In that case, the
> following will work.
>
> $icq =3D "xxx";
> until ($icq =3D~ /^\d*$/) {
> print "ICQ-UIN [num.] [<ENTER> for none] ? ";
> $icq =3D <STDIN>;
> chomp ($icq);
> }
>
Ah, perfect! Thank you! That's what I'm searching for!
> Hope this helps,
Yes, it helps!
> JH
Mit freundlichen Gr=FC=DFen, .~. Open Minds.
with best regards /V\ Open Sources.
// \\ Open Future!
Simon Stiefel /( )\_ I N U X
^ ~ ^
--=20
|Simon Stiefel | Zwerbachstrasse 17 | 72555 Metzingen-Glems | Germany |
|SimonStiefel@nuclear-network.de | http://www.nuclear-network.de |
|ICQ#: 20196644 | phone: +49(0)7123/379070 | fax: +49(0)179/335990106 |
|Tux#: 114751 | PingoS - Linux-User helfen Schulen | Powered by LiNUX |
------------------------------
Date: Sun, 31 Dec 2000 17:07:56 +0100
From: Simon Stiefel <SiStie@nuclear-network.de>
Subject: Re: Matching-Operator question
Message-Id: <Pine.LNX.4.31.0012311702340.891-100000@server.stiefel.priv>
On Sat, 30 Dec 2000, Tad McClellan wrote:
> Simon Stiefel <SiStie@nuclear-network.de> wrote:
>
> >$icq =3D "xxx";
> >while ($icq !~ m/[0-9]*/)
> >{
> > print "ICQ-UIN [num.] [<ENTER> for none] ? ";
> > $icq =3D <STDIN>;
> > chomp ($icq);
> >}
>
>
> >How must I modify the matching-operator to accept <ENTER>?
>
> You have a bigger problem than that.
>
> Your loop body can *never* execute.
>
> m/[0-9]*/ matches the empty string. Every string contains the
> empty string. That pattern matches all possible strings!
> So the m/[0-9]* part is _always_ true.
> So ($icq !~ m/[0-9]*) can never be true.
> So your loop body can never execute.
Ah, I see. Well, now I'm using:
until ($icq =3D~ /^\d*$/)
That works, too.
> last unless length $icq; # zero length
>
> or
>
> last if $icq eq ""; # empty string
This would be a possible solution, too.
Thank you.
> Tad McClellan
Mit freundlichen Gr=FC=DFen, .~. Open Minds.
with best regards /V\ Open Sources.
// \\ Open Future!
Simon Stiefel /( )\_ I N U X
^ ~ ^
--=20
|Simon Stiefel | Zwerbachstrasse 17 | 72555 Metzingen-Glems | Germany |
|SimonStiefel@nuclear-network.de | http://www.nuclear-network.de |
|ICQ#: 20196644 | phone: +49(0)7123/379070 | fax: +49(0)179/335990106 |
|Tux#: 114751 | PingoS - Linux-User helfen Schulen | Powered by LiNUX |
------------------------------
Date: Tue, 02 Jan 2001 17:45:19 GMT
From: Gordon.Haverland@agric.gov.ab.ca
Subject: Memoize internal functions?
Message-Id: <3a521249.355743835@news.gov.ab.ca>
Hi,
I'm working a little signal processing problem. My data is not
sampled regularly, and so I've been working with a discrete Fourier
transform to get into Fourier space. However, my output after
filtering will be regularly spaced, and so a caching of partial
calculations looks like it will be a big win. Can/should I memoize
tha calls to sin/cos, or would I be better to explicitly calculate the
the sin/cos table?
Gord
------------------------------
Date: 3 Jan 2001 13:15:17 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Memoize internal functions?
Message-Id: <92v8l5$eru$2@mamenchi.zrz.TU-Berlin.DE>
<Gordon.Haverland@agric.gov.ab.ca> wrote in comp.lang.perl.misc:
>Hi,
> I'm working a little signal processing problem. My data is not
>sampled regularly, and so I've been working with a discrete Fourier
>transform to get into Fourier space. However, my output after
>filtering will be regularly spaced, and so a caching of partial
>calculations looks like it will be a big win. Can/should I memoize
>tha calls to sin/cos, or would I be better to explicitly calculate the
>the sin/cos table?
I wouldn't expect a hash access (the usual memoizing mechanism) to be
significantly faster than a call to sin() or cos(), but only benchmarks
can tell. You know about the Benchmark module, I suppose.
Anno
------------------------------
Date: 3 Jan 2001 13:49:43 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Memoize internal functions?
Message-Id: <slrn956bfn.f94.abigail@tsathoggua.rlyeh.net>
Gordon.Haverland@agric.gov.ab.ca (Gordon.Haverland@agric.gov.ab.ca) wrote
on MMDCLXXXI September MCMXCIII in <URL:news:3a521249.355743835@news.gov.ab.ca>:
$$ Hi,
$$ I'm working a little signal processing problem. My data is not
$$ sampled regularly, and so I've been working with a discrete Fourier
$$ transform to get into Fourier space. However, my output after
$$ filtering will be regularly spaced, and so a caching of partial
$$ calculations looks like it will be a big win. Can/should I memoize
$$ tha calls to sin/cos, or would I be better to explicitly calculate the
$$ the sin/cos table?
Well, you can memoize the calls to sin/cos, but whether that's a good
idea can only be determined by careful profiling and analysis. And since
Perl relies on the system libraries to do trigs, it might turn out that
where caching the results on one system is a win, it is a loss on another.
Abigail
--
my $qr = qr/^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
$qr =~ s/$qr//g;
print $qr, "\n";
------------------------------
Date: Mon, 01 Jan 2001 14:07:45 -0500
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: min, max (was: Re: Is Perl dying?)
Message-Id: <kevin-E1A837.14074501012001@news.his.com>
In article <umk15t8ds76fmdn07euqpp81987ke4bb0r@4ax.com>, Bart Lateur
<bart.lateur@skynet.be> wrote:
> Randal L. Schwartz wrote:
>
> >Not as pretty, but more efficient, would be:
> >
> > ($x, $y)[ $x <= $y ]
>
> ($x => $y)[ $x <= $y ]
Of course it evaluates both $x and $y twice, which can be problematic,
and doesn't work for more than two items. I'd like to see something
like a 'min' operator that has the same structure as 'sort', i.e. can
take a subroutine that defines the ordering to use plus an array of
items from which the smallest is returned. I tried writing something
like that once but ran into problems when I put it into its own
module... the $a and $b it used weren't in the same package as the ones
the subroutine passed to it used, and I couldn't think of a good way
around that. But I didn't spend very long on it, either.
--
Kevin Michael Vail | a billion stars go spinning through the night,
kevin@vaildc.net | blazing high above your head.
. . . . . . . . . | But _in_ you is the presence that
. . . . . . . . . | will be, when all the stars are dead. (Rainer Maria Rilke)
------------------------------
Date: 01 Jan 2001 11:49:31 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: min, max (was: Re: Is Perl dying?)
Message-Id: <m1itnz833o.fsf@halfdome.holdit.com>
>>>>> "Kevin" == Kevin Michael Vail <kevin@vaildc.net> writes:
Kevin> Of course it evaluates both $x and $y twice, which can be problematic,
Kevin> and doesn't work for more than two items. I'd like to see something
Kevin> like a 'min' operator that has the same structure as 'sort', i.e. can
Kevin> take a subroutine that defines the ordering to use plus an array of
Kevin> items from which the smallest is returned.
use List::Util qw(min); # from the CPAN
$min = min($a, $b);
You might want to take a look at "reduce" in that same module.
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 01 Jan 2001 15:27:27 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: min, max (was: Re: Is Perl dying?)
Message-Id: <m3y9wv3tn4.fsf@mumonkan.sunstarsys.com>
Kevin Michael Vail <kevin@vaildc.net> writes:
> In article <umk15t8ds76fmdn07euqpp81987ke4bb0r@4ax.com>, Bart Lateur
> <bart.lateur@skynet.be> wrote:
>
> > Randal L. Schwartz wrote:
> >
> > >Not as pretty, but more efficient, would be:
> > >
> > > ($x, $y)[ $x <= $y ]
> >
> > ($x => $y)[ $x <= $y ]
>
> Of course it evaluates both $x and $y twice, which can be problematic,
> and doesn't work for more than two items. I'd like to see something
> like a 'min' operator that has the same structure as 'sort', i.e. can
> take a subroutine that defines the ordering to use plus an array of
> items from which the smallest is returned.
Not as pretty, but it should work like sort:
% cat /tmp/try.pl
#!/usr/bin/perl -wl
use strict;
sub compare (&@) {
my $sub = shift;
return undef if @_ < 2;
local ($a, *b) = (shift, \*_ ); # aliases $b to $_
foreach (@_) {
next if $sub -> () >= 0; # next if $a is preferable
$a = $b ; # copy preferred value to $a
}
return $a;
}
my @array = (1,2,-3);
print compare {$a <=> $b} @array;
print compare {$b <=> $a} @array;
__END__
% /tmp/try.pl
2
-3
%
--
Joe Schaefer
------------------------------
Date: Sat, 30 Dec 2000 14:12:57 GMT
From: webqueen, queen of the web <webqueen@my-deja.com>
Subject: Re: mod_perl install problem
Message-Id: <92kqht$c4r$1@nnrp2.deja.com>
I just downloaded this version of mod_perl and tried to install it with
apache 1.3.14, and I get exactly the same error. The INSTALL guide says
apache 1.3.6 or greater is required, then it asks for 1.3.0? Makes no
sense. RH7..
-WQ
In article <91m06s$slo$1@canopus.cc.umanitoba.ca>,
Randy Kobes <randy@theoryx5.uwinnipeg.ca> wrote:
> In comp.lang.perl.misc,
> Chris Johnson <johnson@bonaire.nmr.mgh.harvard.edu> wrote:
>
> > Trying to install mod_perl-1.24 on apache-1.3.14. Tried both
> > with and without mod_ssl-2.7.1-1.3.14 in first. Mod_perl always
gives
> > the following
> > ************* WARNING *************
> > Apache Version 1.3.0 required, aborting...
> > ************* WARNING *************
>
> Try mod_perl-1.24_01.tar.gz from
> http://www.cpan.org/CPAN/authors/id/D/DO/DOUGM/.
>
> best regards,
> randy kobes
>
--
Time is nature's way of preventing everything from happening at once.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 2 Jan 2001 07:52:39 GMT
From: The WebDragon <nospam@nospam.com>
Subject: more info on map function
Message-Id: <92s1c7$8ol$1@216.155.33.34>
does anyone know of any tutorials on the perl 'map' function anywhere,
that go into more detail and examples than the perldocs and "Programming
Perl" does?
I feel like I'm close to understanding how to nest multilevel 'map's
together, but would appreciate some further clarification that I could
go read somewhere.
it's a relatively simple function, but I've seen you folks use them in
startling ways that I'd really love to wrap my brain around. :)
AdvThanksance,
--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.
------------------------------
Date: Tue, 02 Jan 2001 08:04:19 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: more info on map function
Message-Id: <x7zoha8jng.fsf@home.sysarch.com>
>>>>> "TW" == The WebDragon <nospam@nospam.com> writes:
TW> does anyone know of any tutorials on the perl 'map' function
TW> anywhere, that go into more detail and examples than the perldocs
TW> and "Programming Perl" does?
there is one here:
http://tlc.perlarchive.com/0010/01.shtml
i bet the perl cookbook and effective perl programming have plenty of
examples.
the best way to think about map is that it transforms one list into
another. you provide the function (e.g. the map) which does the
transformation and the input list. you get back the new transformed
list.
so map output can have fewer, the same or even more elements than its
input. all it is a expression or code block that is applied to each
element of the input list and the results are pushed onto the output
list.
very simple in concept. very powerful in effect.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Tue, 2 Jan 2001 07:12:49 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: more info on map function
Message-Id: <slrn953he1.e6p.tadmc@magna.metronet.com>
Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "TW" == The WebDragon <nospam@nospam.com> writes:
>
> TW> does anyone know of any tutorials on the perl 'map' function
> TW> anywhere, that go into more detail and examples than the perldocs
> TW> and "Programming Perl" does?
>the best way to think about map is that it transforms one list into
>another.
It may also be helpful to recast the map() into a foreach()
so you can see it in terms that are more familiar.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 02 Jan 2001 18:12:31 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: more info on map function
Message-Id: <x7wvcd9628.fsf@home.sysarch.com>
>>>>> "TM" == Tad McClellan <tadmc@metronet.com> writes:
TM> Uri Guttman <uri@sysarch.com> wrote:
>>>>>>> "TW" == The WebDragon <nospam@nospam.com> writes:
>>
TW> does anyone know of any tutorials on the perl 'map' function
TW> anywhere, that go into more detail and examples than the perldocs
TW> and "Programming Perl" does?
>> the best way to think about map is that it transforms one list into
>> another.
TM> It may also be helpful to recast the map() into a foreach()
TM> so you can see it in terms that are more familiar.
that is fairly easy:
sub map(&@) {
my ( $code ) = shift ;
my @map_out ;
for ( @_ ) {
push( @map_out, &$code ) ;
}
return @map_out ;
}
i hope that explains it more. it is a very simple concept but very
powerful.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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.
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 V9 Issue 5233
**************************************