[12022] in Perl-Users-Digest
Perl-Users Digest, Issue: 5622 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 10 21:07:22 1999
Date: Mon, 10 May 99 18:00:16 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 10 May 1999 Volume: 8 Number: 5622
Today's topics:
ANNOUNCE: PerlMonth - Web-Based Perl Magazine [www.perl bthak@bascom.com
Re: File::Find non-functional when passing arguments to (Andrew Allen)
Re: File::Find non-functional when passing arguments to (M.J.T. Guy)
Help processing a file csartori@my-dejanews.com
Re: If first record....Please read!!! jeffrey_f@my-dejanews.com
Re: Making executables from .pl files? (Chris Costello)
Re: Module Dependancies and older Perl Releases (Text:: (Charles R. Thompson)
Re: Module Dependancies and older Perl Releases (Text:: (Charles R. Thompson)
Need some help with passive ftp. <pjdurai@my-dejanews.com>
perl command line args <sgutti@usa.net>
Re: perl command line args (Bob Trieger)
Re: PERL Searching Strings <tchrist@mox.perl.com>
Re: PERL Searching Strings <upsetter@ziplink.net>
print "Location: $filename\n\n"; (W Barksdale)
set uid:gid for file from CGI running on intranet <pleddy@leddy.org>
Re: Sorting is too slow for finding top N keys... - BEN (Larry Rosler)
We need your help ( doc, link , etc ) !!! <fred@decatomb.com>
Re: why won't this cgi script work? <Care227@ibm.net>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 10 May 1999 22:24:32 GMT
From: bthak@bascom.com
Subject: ANNOUNCE: PerlMonth - Web-Based Perl Magazine [www.perlmonth.com]
Message-Id: <7h7mav$nbp$1@nnrp1.deja.com>
Hi,
PerlMonth is a new, monthly web-based magazine which
will focus on providing in-depth articles on various
topics written by experienced writers from throughout
the Perl community. Each issue of PerlMonth will
bring you articles on MacPerl, Perl/TK, Using
Databases, Modules, and innovative uses of this
powerful programming language. PerlMonth will also
bring you a variety of other resources such as book
reviews, useful links, and other sources of
information available to Perl programmers.
PerlMonth was developed for the Perl developer.
Your feedback will help us keep our commitment to
provide you with the most useful information that we
can. Let us know what you as a Perl developer would
like to see in a magazine such as this one.
This month's issue includes articles from Vicki
Brown, Paul Vining, Dave cross, Mark-Jason Dominus, Kurt D.
Starsinic, Stephen O. Lidie, and Steven McDougall.
I would like to thank them for taking time out of
their busy schedules to provide insight into their expert
opinions and experience.
Availability:
PerlMonth is available at the following URL:
http://www.perlmonth.com/
Contact Information:
General information info@perlmonth.com
Suggestions suggest@perlmonth.com
Write for PerlMonth authors@perlmonth.com
Feedback feedback@perlmonth.com
Baiju Thakkar
Just use Perl;
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: 10 May 1999 22:43:58 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: File::Find non-functional when passing arguments to &wanted
Message-Id: <7h7nfe$l18$1@fcnews.fc.hp.com>
Bart Lateur (bart.lateur@skynet.be) wrote:
: Andrew Allen wrote:
: >No, it's doing exactly what you want. How obvious would you need the
: >syntax to be before the warning is squelched? Would \(&foo(3))
: >suffice? Or would you insist upon \scalar(&foo(3))
: sub foo { shift };
: print \foo; # undef
: -> SCALAR(0x13b1e0)
: print \foo(3); # 3
: -> SCALAR(0x13b1e0)
: print \&foo(3); # 3
: -> SCALAR(0x13b1e0)
: print \&foo;
: -> CODE(0xffc12238)
: Well there's a bizarre exception alright. "&foo" is the only syntax that
: returns a code ref, WITHOUT excuting the sub. The others all return a
: reference to the value returned by the sub call.
Exactly how it should be. I fail to see the "bizarre exception"
here. \&foo returns a code ref. Period. Just like \$foo returns a
scalar ref. Where's the exception? perlsub even documents it in an
oblique sort of way:
A subroutine may be called using the "&" prefix. The "&" is optional
in modern Perls, and so are the parentheses if the subroutine has been
predeclared. (Note, however, that the "&" is NOT optional when you're
just naming the subroutine, such as when it's used as an argument to
defined() or undef().
**or the \ operator** (my suggested addition)
: I think that's not right.
Why? I'm still failing to understand your precise objection.
: I personally think that anything (dubious) inbetween
: print \(&foo(3));
: -> function call, reference to result
except this would appear to give &foo a list context (but see below).
: and
: print &foo;
: -> no function call, but reference to sub
This calls &foo for me. Did you mean \&foo?
: should give a warning. BTW these two do as I describe.
Really?
Now playing around with this I found something I _do_ consider a bug:
perl5 -e 'sub a {wantarray?1:0}; $a=&a(); $b=\&a(); $c=\a; print $a,$$b,$$c'
prints
011
I'm on (perl -v) (if it matters):
This is perl, version 5.005_02 built for PA-RISC1.1
Andrew
------------------------------
Date: 10 May 1999 23:46:01 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: File::Find non-functional when passing arguments to &wanted
Message-Id: <7h7r3p$ph0$1@pegasus.csx.cam.ac.uk>
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>You probably mean: use
>
> \do {my $foo = 15}
>
>instead... Not that pretty too...
Of course not. What I meant was: use
(15 =~ /(.*)/ && \$1)
Mike Guy
------------------------------
Date: Mon, 10 May 1999 22:15:38 GMT
From: csartori@my-dejanews.com
Subject: Help processing a file
Message-Id: <7h7lq8$mur$1@nnrp1.deja.com>
Hi, there: I am new to Perl. I will appreciate if someone can give me a
hand.
Thanks in advance,
Claudio
Here is the code of my script as well as the Input & Output files:
# Description: This program looks for the words
# a, al, del, con, y on the input file.
# For every word that is matched on the input file,
# the program prints 1) the chunk of string that preceeds
# that word; 2) the chunk of string that follows that word.
# Current problem: The 2nd print doesn4t work correctly,
# because it does not print it.
use FileHandle;
$/ = ""; # paragraph mode
$fhw = new FileHandle;
if ($fhw->open("+> newterm.txt")) {
select($fhw); # Sets this handle as the standard output
while (<>) {
while ( /\b(a|al|de|con|y)\b/gi ) {
print "$` precedes $1.\n";
print "$4 follows $1.\n";
}
}
$fhw->close;
}
--------------------------------------------
Here is the Input File
--------------------------------------------
Hola que tal .
Si del campo para hoy.
A las cuatro de nuevo.
Sin prisa y con ganas.
--------------------------------------------
Here is the Output File
--------------------------------------------
Hola que tal .
Si del campo para hoy.
precedes A.
follows A.
Hola que tal .
Si del campo para hoy.
A las cuatro precedes de.
follows de.
Hola que tal .
Si del campo para hoy.
A las cuatro de nuevo.
Sin prisa precedes y.
follows y.
Hola que tal .
Si del campo para hoy.
A las cuatro de nuevo.
Sin prisa y precedes con.
follows con.
--------------------------------------------
Here is what I am looking for
--------------------------------------------
Hola que tal .
Si del campo para hoy.
precedes A.
las cuatro de nuevo.
Sin prisa y con ganas. follows A.
Hola que tal .
Si del campo para hoy.
A las cuatro precedes de.
nuevo.
Sin prisa y con ganas. follows de.
...
--------------------------------------------
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Tue, 11 May 1999 00:14:59 GMT
From: jeffrey_f@my-dejanews.com
Subject: Re: If first record....Please read!!!
Message-Id: <7h7sq1$s3t$1@nnrp1.deja.com>
In article <MPG.11a00a13299a83b4989682@news>,
design@raincloud-studios.com (Charles R. Thompson) wrote:
> In article <7h5a3i$4cs$1@nnrp1.deja.com>, jeff@indexfinger.com says...
>
> > I need the "If
> > its the first record in the database, it should do
> > one
> > thing. If not, do something else." part.
>
> if ($whatever_designates_your_first_record){
> # do stuff
> }else{
> # do other stuff
> }
This does whats in #do stuff if its the first record or not!!
>
> > I appreciate all help.
>
> no prob. If I can be any more vague in return, just ask.
>
> --
> Charles R. Thompson
> RainCloud Studios
> --posted with evaluation copy of MicroPlanet Gravity(PC)--
> --please email if software causes problems in newsgroup--
>
Jeffrey L. Farber
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Mon, 10 May 1999 22:52:22 GMT
From: chris@holly.dyndns.org (Chris Costello)
Subject: Re: Making executables from .pl files?
Message-Id: <slrn7jeorg.ms8.chris@holly.dyndns.org>
In article <B6IZ2.320$%j4.1090@news.rdc1.sfba.home.com>, Stephen Warren wrote:
> Not that I've ever used it, but it sounds like you need to:
>
> a) Use some other command-line options to get around it (read docs)
> b) Distribute those modules with the .exe file (and probably setup the
> 'module path' correctly)
Read the manual page for perlcc, it has all the information
you need.
>
> --
> Stephen Warren, Snr Systems Engineer, Technology House, San Francisco
> mailto:swarren@techhouse.com http://www.techhouse.com/
> mailto:swarren@wwwdotorg.org http://www.wwwdotorg.org/
> MIME, S/MIME and HTML mail are acceptable
>
>
>
--
Chris Costello
You have a tendency to feel you are superior to most computers.
------------------------------
Date: Mon, 10 May 1999 22:52:58 GMT
From: design@raincloud-studios.com (Charles R. Thompson)
Subject: Re: Module Dependancies and older Perl Releases (Text::Query::Advanced example)
Message-Id: <MPG.11a12e9f130500e0989687@news>
In article <MPG.11a11241937655b4989686@news>, Charles R. Thompson says...
> 2) Eric Bohlman? Do you mind popping into this? Instead of reinventing
> the wheel, I'd much rather use your Text::Query::Advanced module for my
> search script. What limitations are really there for this module on an
> older release? The newest says the requirement is 5.005. Is that *really*
> true, or does it fall in the range of question 1?
I gave it the ol' hackaroo and only generated errors in a very short area
of the package itself when removing the 5.005 requirement.
sub build_final_expression {
my ($self,$t1)=@_;
my $t;
# Scalar found where operator expected at
# end of line (Missing operator before ?)
$t=($self->{parseopts}{-case})?'':'(?i)';
# Syntax error near $t$t1
# never seen qr... will have to look around.
return qr/$t$t1/s;
}
# somewhere in here $r $l requires explicit package name.
# For some odd reason it claims the error is up there
# at line 168 with the others, but they are all below
# this sub and in other subs below it.
sub build_expression {
my ($self,$l,$r)=@_;
#factor any common "^" out of the disjunction
#This really speeds up matching
if (substr($l,0,1) eq '^' and substr($r,0,1) eq '^') {
return '^(?:'.substr($l,1).'|'.substr($r,1).')';
} else {
return "$l|$r";
}
}
If anyone could shine some light on how to wrangle this thing to
5.003_02, you'd be saving my sanity.
--
Charles R. Thompson
RainCloud Studios
"That? That's no script. That's your attempt at a rather complex README
file."
------------------------------
Date: Tue, 11 May 1999 00:48:00 GMT
From: design@raincloud-studios.com (Charles R. Thompson)
Subject: Re: Module Dependancies and older Perl Releases (Text::Query::Advanced example)
Message-Id: <MPG.11a1483c5efee5e9989688@news>
In article <MPG.11a12e9f130500e0989687@news>, Charles R. Thompson says...
> If anyone could shine some light on how to wrangle this thing to
> 5.003_02, you'd be saving my sanity.
After reading through the CookBook, I've gotten as far as understanding
qr// to be a new feature in 5.005 (thus requiring the version) based off
of the older RegExp module.
My thought was to revamp Advanced.pm to use the RegExp module. Since
RegExp was built for the earlier releases, I'm thinking a bit of research
may result in a backwards compatible Advanced Query module.
I have all the components now except for DynaLoader, which is required by
RegExp. The CPAN folder for this module is empty and it does not appear
in my /usr/lib/Perl5 or any subdirectories.
Any ideas where I might get my hands on it?
--
Charles R. Thompson
RainCloud Studios
"That? That's no script. That's your attempt at a rather complex README
file."
------------------------------
Date: Mon, 10 May 1999 22:52:06 GMT
From: pj durai <pjdurai@my-dejanews.com>
Subject: Need some help with passive ftp.
Message-Id: <7h7nul$oea$1@nnrp1.deja.com>
Greetings,
I am trying to write a small script to use from my makefiles. It just
uploads a give file to an ftp server. The input is given as an url and
a filename.
I need to use Passive Mode for a site. Though the code works mostly
(with anonymous logins), it doesnt work where I need to use passive
mode. ( I am able to work with this site with a program called
AbsoluteFtp. Pretty much nothing else works.).
Can somebody take a look at this script and see if anything is wrong?
Appreciate your time,
thank you,
pj
---start
use Net::FTP;
use Getopt::Std;
use URI::URL;
# sample command
# perl -w ftp-put.pl -u "ftp://anonymous:duraip@ftp.microsoft.com/" -f
disclaimer.txt
#main ()
{
my($url_string,$filename);
my($url);
getopt("u:f:");
$url_string = $opt_u;
$filename = $opt_f;
$url = new URI::URL($url_string);
$ftp = Net::FTP->new($url->host,Passive , 'true');
$ftp->login($url->user,$url->password);
$ftp->cwd($url->path);
print join("\n",$ftp->dir()), "\n";
#$ftp->get($filename);
#$ftp->put ($filename);
$ftp->quit;
}
--- end
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Mon, 10 May 1999 22:54:25 GMT
From: "gwinsock" <sgutti@usa.net>
Subject: perl command line args
Message-Id: <BsJZ2.1518$xa.17255@c01read02-admin.service.talkway.com>
hi all,
Iam a newbie to perl , and I have a question regarding PERL command
line arguements. I want to send perl with command line arguements and
some of those have spaces in
between, and I think perl treats space as a delimitter, so if I have 3
arguements and im calling
xxx.prl 1 kansas city 3
perl takes kansas as one parameter and city as aonther parameter,...how
can i come across that, is there anyway i can force perl to interpret
certain list of words as a single
arguement?? so can i change its interpretation of arguements??? If you
guys have any ideas, please put them across,
thanks in advance,
sri
sgutti@iname.com
--
Posted via Talkway - http://www.talkway.com
Exchange ideas on practically anything (tm).
------------------------------
Date: Tue, 11 May 1999 00:46:23 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: perl command line args
Message-Id: <7h7tid$cc2$1@holly.prod.itd.earthlink.net>
[ courtesy cc sent by mail if address not munged ]
"gwinsock" <sgutti@usa.net> wrote:
>hi all,
>Iam a newbie to perl , and I have a question regarding PERL command
>line arguements. I want to send perl with command line arguements and
>some of those have spaces in
>between, and I think perl treats space as a delimitter, so if I have 3
>arguements and im calling
>
>xxx.prl 1 kansas city 3
>
>perl takes kansas as one parameter and city as aonther parameter,...how
>can i come across that, is there anyway i can force perl to interpret
>certain list of words as a single
>arguement?? so can i change its interpretation of arguements??? If you
>guys have any ideas, please put them across,
Throw some quotes around the string.
IE: "Kansas City"
------------------------------
Date: 10 May 1999 16:01:27 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: PERL Searching Strings
Message-Id: <37375737@cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Mike Gibson <mgibson@newbridge.com> writes:
:if(($a{'managername'} eq $in{'manager'}) || ($a{'managername'} =~
:/^$in{'manager'}/i))
CGI.pm does not load %in. You must be doing something wrong.
--tom
--
Those who do not understand Unix are condemned to reinvent it, poorly.
-- Henry Spencer
"In any organisation, there will always be one person who knows what is going
on. This person must be fired."
------------------------------
Date: Mon, 10 May 1999 22:52:42 GMT
From: Scratchie <upsetter@ziplink.net>
Subject: Re: PERL Searching Strings
Message-Id: <_qJZ2.1321$9L5.483639@news.shore.net>
Tom Christiansen <tchrist@mox.perl.com> wrote:
: [courtesy cc of this posting sent to cited author via email]
: In comp.lang.perl.misc,
: Mike Gibson <mgibson@newbridge.com> writes:
: :if(($a{'managername'} eq $in{'manager'}) || ($a{'managername'} =~
: :/^$in{'manager'}/i))
: CGI.pm does not load %in.
It can.
--Art
--
--------------------------------------------------------------------------
National Ska & Reggae Calendar
http://www.agitators.com/calendar/
--------------------------------------------------------------------------
------------------------------
Date: Mon, 10 May 1999 23:08:19 GMT
From: wb_1999@yahoo.com (W Barksdale)
Subject: print "Location: $filename\n\n";
Message-Id: <7h7p4f$9rr$1@nntp4.atl.mindspring.net>
Keywords: gzip, zip, tar, jar
I am using 'print "Location: $filename\n\n";' in a perl script to download a
file. As long as the file has a .zip extension the download works fine, but
when the extension is .gz strange things begin to happen.
In Netscape the file is written to the browser window instead of to disk. .gx
is a registered extension for mime type application/x-gzip and is to be
handled by winzip. Just like .zip.
With IE even stranger things happen. The file is saved with a name change
(from SubC10d_tar.gz to SubC10d_tar(1).gz) and the .tar file contained in the
gz is opened and the java .jar file within the .tar is opened and expanded.
The collateral directories and files in the tar are gone.
The transfer is from a linux system to a windows system
Anyone have any idea what's going on here?
Thanks,
Wayne
------------------------------
Date: Tue, 11 May 1999 00:49:07 GMT
From: Paul Leddy <pleddy@leddy.org>
Subject: set uid:gid for file from CGI running on intranet
Message-Id: <37377E4E.FF57C00E@leddy.org>
i have a little txt editor i wrote for out intranet that uses an html
forms interface running on apache.
i need to know how i can get this "nobody" cgi process to write a file
which has the owner and group set to a real person and group on our
system.
i can already get the uid (numerical) of the user based on a selection
they make on an html form, but i dont know how i can write/create a file
which is owned by that uid/person. i can get the uid (numerical) from
the name the user types in (trust is not an issue here) using getpwuid.
there is only one possibility for the group. i see that i might be able
to use setpgrp to change the cgi process gid, though i have not tested
this yet.
all is behind a firewall, so no worries there.
cc email to pcleddy@yahoo.com is appreciated.
------------------------------
Date: Mon, 10 May 1999 17:45:34 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Sorting is too slow for finding top N keys... - BENCH
Message-Id: <MPG.11a11d8ce47dcf2b989a29@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7h6ij5$dfr$1@news.mch.sbs.de> on Mon, 10 May 1999 12:14:49
GMT, Michel Dalle <michel.dalle@usa.net> says...
...
> Benchmark: timing 100 iterations of Bart1, Larry1, Larry2, Marko2, Michel3...
> Bart1: 59 secs (59.11 usr 0.00 sys = 59.11 cpu)
> Larry1: 72 secs (71.58 usr 0.00 sys = 71.58 cpu)
> Larry2: 94 secs (94.52 usr 0.00 sys = 94.52 cpu)
> Marko2: 110 secs (109.57 usr 0.00 sys = 109.57 cpu)
> Michel3: 114 secs (114.64 usr 0.00 sys = 114.64 cpu)
>
> with :
> Bart1 : reverse the hash (since many of the values are identical in this case)
> Larry1 : keep top N keys in array and splice when necessary
> Larry2 : generalisation of Larry1 for arrays&hashes, max&min, numeric&alpha
> Michel3 : forefather (not really perl-like) of Larry1
> Marko2 : quick select algorithm
>
> Out of range :
> Michel1 : simple Perl sort (!) - xx minutes
> Michel2 : sort and slice for each key - 19 seconds
> Andy1 : sort and slice when needed - 13 seconds
>
> Note : Marko1 & Marko2 sort an array rather than a hash, so I had to
> modify it. Since I'm not another Perl hacker (and the source also has to
> be "perlified" according to the todo-list of Marko), my modifications are
> probably pretty inefficient. The underlying algorithm seems to be pretty
> fast, though...
>
> If anyone could make a 'Marko3' for hashes, I could test it more fairly :-)
> Other suggestions are also welcome...
I've been too occupied with fiddling with my own to look at Marko's.
Below is my third version, differing from the previous in adding the
code to handle a sort-sub (as suggested by Sam Holden), in addition to
the (faster) ascending and descending lexicographic and numeric sorts.
Because of the overhead in calling the sort-sub as compared to executing
the comparisons in line, binary insertion into the N-element result
array turned out to be better than linear insertion, more so as N gets
larger.
Several simple test cases are added, as well as my encapsulation of the
original data (thanks for posting them) and a benchmark comparing the
sort-sub to the internal sort.
I haven't found a sort-extremes module under CPAN Sort::..., and neither
Knuth Vol. 3 nor Sedgewick seems to have an algorithm. I will soon
submit this to the Perl Function Repository, and perhaps make it into a
module as a training exercise.
#!/usr/local/bin/perl -w
use strict;
sub extremes { # Return the N extreme-valued elements of an array or a
hash.
my ($ref, $n, $num, $max) = @_;
$n && $n > 0 or return ();
my $refref = $ref && ref $ref || "";
my $array = $refref eq 'ARRAY' ? 1 : $refref eq 'HASH' ? 0 : die
"First argument '$ref' isn't a reference to an array or a hash.\n";
my ($j, @out) = 0;
if ($num && ref $num eq 'CODE') { # Binary insertion.
while (defined(my $key = $array ? $ref->[$j++] : each %$ref)) {
next if @out == $n &&
do { ($a, $b) = ($key, $out[-1]); &$num > 0 };
my ($lo, $hi, $i) = (0, scalar @out);
for ($i = int($hi/2); $lo < $hi; $i = $lo + int(($hi - $lo)/2)) {
($a, $b) = ($key, $out[$i]);
my $comp = &$num;
if ($comp > 0) { $lo = $i + 1 }
elsif ($comp < 0) { $hi = $i }
else { last };
}
splice @out, $i, 0, $key;
--$#out if @out > $n;
}
return @out;
}
$max = $max ? -1 : +1; # Descending sort if max is TRUE.
if ($array) { # Linear insertion (fewer perl-ops).
while (defined(my $key = $ref->[$j++])) {
next if @out == $n && $max == ($num ? $key <=> $out[-1]
: $key cmp $out[-1]);
my $i = 0;
++$i while $i < @out && $max == ($num ? $key <=> $out[$i]
: $key cmp $out[$i]);
splice @out, $i, 0, $key;
--$#out if @out > $n;
}
} else { # Linear insertion (fewer perl-ops).
while (my ($key, $val) = each %$ref) {
next if @out == $n && $max == ($num ? $val <=> $ref->{$out[-1]}
: $val cmp $ref->{$out[-1]});
my $i = 0;
++$i while $i < @out &&
$max == ($num ? $val <=> $ref->{$out[$i]}
: $val cmp $ref->{$out[$i]});
splice @out, $i, 0, $key;
--$#out if @out > $n;
}
}
@out
}
# extremes() returns the extreme N values of a list, or the keys of the
# extreme N values of a hash. When the aggregate is very large and the
# number of values N is relatively small, this function is much more
# efficient than sorting the entire aggregate and returning a slice from
# the appropriate end of the sorted list.
#
# extremes(ref, n, num, max)
# ref = reference to array or hash
# n = maximum number of elements to return
# num = sort numeric if TRUE, sort lexicographic if FALSE
# max = maxima descending if TRUE, minima ascending if FALSE
#
# Trailing FALSE arguments may be omitted. More complex sorting
# comparisons may be done using a standard sorting subroutine as the
# third argument.
#
# The algorithm for this function, and an initial implementation, were
# presented by Michel Dalle, 8 May 1999.
#
# Larry Rosler, 10 May 1999
#*********************************************************************
my @array = ( 'A' .. 'Z', 'A' .. 'Z' );
print extremes(\@array, 20, sub { $b cmp $a }), "\n";
print extremes(\@array, 20, 0, 1), "\n"; # lexicographic, maxima
print extremes(\@array, 20), "\n"; # lexicographic, minima
my %hash;
@hash{ 'a' .. 'z', 'A' .. 'Z' } = ( 1 .. 26, 1 .. 26 );
print extremes(\%hash, 20, sub { $hash{$a} <=> $hash{$b} }), "\n";
print extremes(\%hash, 20, 1), "\n"; # numeric, minima
print extremes(\%hash, 20, 1, 1), "\n"; # numeric, maxima
%hash = ();
for (my $key = 'aaaa'; <DATA>; ) {
my ($value, $number) = /(\d+)\s+(\d+)/;
$hash{$key++} = $value while $number--;
}
print scalar keys %hash, "\n"; # (that's 31012 entries)
print map("$hash{$_} ", extremes(\%hash, 20, 1, 1)), "\n";
use Benchmark;
timethese(1 << (shift || 0), {
Internal => sub { extremes(\%hash, 20, 1, 1) },
Sortsub => sub { extremes(\%hash, 20,
sub { $hash{$b} <=> $hash{$a} }) },
});
__END__
1 22879
2 4721
3 1571
4 667
5 361
6 219
7 130
8 99
9 62
10 47
11 44
12 29
13 29
14 28
15 22
16 21
17 11
20 9
22 9
18 7
28 6
21 4
27 4
31 4
23 3
25 3
30 3
37 3
19 2
24 2
29 2
32 2
41 2
26 1
33 1
50 1
52 1
56 1
59 1
79 1
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 10 May 1999 20:32:39 -0300
From: "Fridirick Giasson" <fred@decatomb.com>
Subject: We need your help ( doc, link , etc ) !!!
Message-Id: <37376C97.6CA63B50@decatomb.com>
Hello,
We want to expand this information base and to improve our
document libraries, our links and our newsgroup section.
We would like your help to achieve this. With you, we will be helping a
lot of the world's coders. Our goal is to help you develop cutting edge
applications, by providing the resources you need so you will never give
up. If you have an URL to add or a discussion group address, please send
it to:
dev@decatomb.com
If you have a document ( test, html, doc, etc), attach it to an email
addressed to:
dev@decatomb.com
developper coner : http://www.decatomb.com/dev/
thank's you for your help
Fridirick Giasson
Delopper of Decatomb Production
fred@decatomb.com
------------------------------
Date: Mon, 10 May 1999 18:39:49 -0400
From: Drew Simonis <Care227@ibm.net>
Subject: Re: why won't this cgi script work?
Message-Id: <37376035.B2EE6D07@ibm.net>
Then why read it into a filehandle?
Bart Lateur wrote:
>
> Drew Simonis wrote:
>
> >And, while I'm here, why are you reading a file into a scalar?
>
> Surely, the file contains just a number...
>
> Bart.
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 5622
**************************************