[10400] in Perl-Users-Digest
Perl-Users Digest, Issue: 3993 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 16 14:02:31 1998
Date: Fri, 16 Oct 98 11:00:18 -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 Fri, 16 Oct 1998 Volume: 8 Number: 3993
Today's topics:
Re: Assigning to $! <jdporter@min.net>
Re: Camel Pub (was Re: Raleigh.pm has registered) <uri@camel.fastserv.com>
Re: Combining two @array's (Craig Berry)
Re: grrrrr, why not while(<blah>) (Larry Wall)
Re: grrrrr, why not while(<blah>) (Larry Rosler)
Re: grrrrr, why not while(<blah>) <merlyn@stonehenge.com>
Re: Issuing remote commands trough sockets. (David B. White)
Need help with this script w.wilson@mailexcite.com
Re: newbie: getting the wrong month out of localtime() (Larry Rosler)
Re: Perl FAQ - error found in "#How_do_I_get_a_file_s_t <ajohnson@gatewest.net>
Re: problem with "use lib" (Mark-Jason Dominus)
Re: Slow Sort? (Larry Rosler)
Re: Slow Sort? <eashton@bbnplanet.com>
Re: Slow Sort? <matt@whiterabbit.co.uk>
Re: Slow Sort? <eashton@bbnplanet.com>
Re: Sorry <cmcurtin@interhack.net>
Re: sorting <jdporter@min.net>
Re: sorting <uri@camel.fastserv.com>
SUMMARY: Perl5 on Solaris reading MS Access Database <slpalmer@NOSPAM.flex.net>
Re: The space deletion woes... <r28629@email.sps.mot.com>
Re: The space deletion woes... <eashton@bbnplanet.com>
Re: Using a variable in a grep search <tchrist@mox.perl.com>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 16 Oct 1998 13:40:10 -0400
From: John Porter <jdporter@min.net>
Subject: Re: Assigning to $!
Message-Id: <362784FA.7514E2D9@min.net>
45jhp wrote:
>
> I want to call one perl script from another and capture any error
> messages if the called script terminates abnormally. Is there any way of
> using $! as I would with a system call ? The docs seem to say that you
> can assign to $! but my simple tests fail ... can someone offer some
> enlightment ??
You can assign to $!; if you assign a number to it, then the
"stringized" form will change to stay in sync with the number.
But what makes you think that will solve your problem?
@output_from_bar = `bar.pl`;
And in bar.pl, dup STDERR onto STDOUT.
Or you might prefer to have a shell do that for you.
--
John "Gashlycrumb" Porter
"A fugitive and lurid gleam
Obliquely gilds the gliding stream." -- EG
------------------------------
Date: 16 Oct 1998 13:34:38 -0400
From: Uri Guttman <uri@camel.fastserv.com>
Subject: Re: Camel Pub (was Re: Raleigh.pm has registered)
Message-Id: <saraf2wpg0h.fsf@camel.fastserv.com>
>>>>> "LB" == Leon Brocard <l.brocard@elsevier.nl> writes:
LB> Stuffed Camel
LB> 1 whole camel, medium size
LB> 1 whole lamb, large size
LB> 20 whole chickens, medium size
LB> 60 eggs
LB> 12 kilos rice
LB> 2 kilos pine nuts
LB> 2 kilos almonds
LB> 1 kilo pistachio nuts
LB> 110 gallons water
LB> 5 pounds black pepper
LB> Salt to taste
LB> Skin, trim and clean camel (once you get over the hump), lamb
LB> and chicken. Boil until tender. Cook rice until fluffy. Fry nuts
LB> until brown and mix with rice. Hard boil eggs and peel. Stuff
LB> cooked chickens with hard boiled eggs and rice. Stuff the cooked
LB> lamb with stuffed chickens. Add more rice. Stuff the camel with
LB> the stuffed lamb and add rest of rice. Broil over large charcoal
LB> pit until brown. Spread any remaining rice on large tray and
LB> place camel on top of rice. Decorate with boiled eggs and nuts.
LB> Serves friendly crowd of 80-100.
this recipe has been posted here before. i wonder if anyone who
uses perl has EVER tasted it? anyone from camel eating lands lurking
here?
uri
--
Uri Guttman Fast Engines -- The Leader in Fast CGI Technology
uri@fastengines.com http://www.fastengines.com
------------------------------
Date: 16 Oct 1998 17:33:04 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Combining two @array's
Message-Id: <70800g$dks$1@marina.cinenet.net>
al.woods@pbi.ab.ca wrote:
: I'm probably looking for a complex solution where a simple one is available
: but is there an easy way to combine 2 @array's?
Create new array @c containing contents of @a, followed by contents of @b:
@c = (@a, @b);
Make @a contain original contents of @a, followed by contents of @b:
push @a, @b;
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| "Ripple in still water, when there is no pebble tossed,
nor wind to blow..."
------------------------------
Date: 16 Oct 1998 10:20:53 -0700
From: larry@kiev.wall.org (Larry Wall)
Subject: Re: grrrrr, why not while(<blah>)
Message-Id: <707v9l$5kg@kiev.wall.org>
In article <707smp$ohv$1@csnews.cs.colorado.edu>,
Tom Christiansen <tchrist@mox.perl.com> wrote:
>In comp.lang.perl.misc, Randal Schwartz <merlyn@stonehenge.com> writes:
>:>>>>> "Daniel" == Daniel Vesma <daniel.vesma@thewebtree.com> writes:
>:
>:Daniel> ($tempONE, $tempTWO, $tempTHREE) = split(/^/, $_);
>:
>:Hmm. What do you expect this to do? There's only one beginning of
>:string, so splitting there won't ever really return many elements.
>
>Strike two.
It's another at-bat, silly. Randal's already had several base hits in
between.
Larry
------------------------------
Date: Fri, 16 Oct 1998 10:37:01 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: grrrrr, why not while(<blah>)
Message-Id: <MPG.1091241ab5ce159a98981c@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <8clnmg2zyz.fsf@gadget.cscaper.com> on Fri, 16 Oct 1998
17:12:08 GMT, Randal Schwartz <merlyn@stonehenge.com> says...
...
> I'm gonna file this as a bug then. There's only one beginning
> of string. The behavior you've just shown should be true only
> when you use /m, as in:
>
> @a = split /^/m, $_;
>
> I posted my response based on documentation. Where is it documented
> that there's an auto /m on split? If not, then it's a bug in either
> the docs or the code.
In fact, the documentation on 'split' explicitly shows the 'm', which
might well lead one to expect the opposite behavior if there is no 'm':
If you had the entire header of a normal Unix email message in $header,
you could split it up into fields and their values this way:
$header =~ s/\n\s+/ /g; # fix continuation lines
%hdrs = (UNIX_FROM => split /^(\S*?):\s*/m, $header);
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 16 Oct 1998 17:12:08 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: grrrrr, why not while(<blah>)
Message-Id: <8clnmg2zyz.fsf@gadget.cscaper.com>
>>>>> "Tom" == Tom Christiansen <tchrist@mox.perl.com> writes:
Tom> $_ = "line1\nline2\nline3\n";
Tom> ($t1, $t2, $t3) = split(/^/, $_);
Tom> print "one is $t1\n";
Tom> print "two is $t2\n";
Tom> print "three is $t3\n";
Tom> produces:
Tom> one is line1
Tom> two is line2
Tom> three is line3
I'm gonna file this as a bug then. There's only one beginning
of string. The behavior you've just shown should be true only
when you use /m, as in:
@a = split /^/m, $_;
I posted my response based on documentation. Where is it documented
that there's an auto /m on split? If not, then it's a bug in either
the docs or the code.
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 16 Oct 1998 17:06:32 GMT
From: dbwhite@btv.ibm.com (David B. White)
Subject: Re: Issuing remote commands trough sockets.
Message-Id: <707ueo$tt4$1@mdnews.btv.ibm.com>
In article <36193336.41C6@mlink.net>,
Farley Christian <cfarley@mlink.net> writes:
> How can i have a script execute a command on a remote machine (like rsh)
> and collect back the output from that command?
To use the rsh command to execute the command directly on a remote machine,
try section 16.9, "Controlling the Input, Output, and Error of Another Program"
in the "Perl Cookbook" written by Tom Christiansen & Nathan Torkington.
(ISBN 1-56592-243-3 published by O'Reilly)
Be advised that the STDERR and STDOUT of the remote process will appear
as the STDOUT of the local process (just like a remote console) and that
the order of the messages is dependent on who flushes when...
If you want to write a client/server that allows the local box to execute
a Remote Procedure Call, see Chapter 13, "Networking: Implementing RPC"
in "Advanced Perl Programming" by Sriram Srinivasan. (ISBN 1-56592-220-4
published by O'Reilly; example code available from www.oreilly.com)
If you decide to run your server as a daemon, see the "Perl Cookbook"
section 17.15, "Making a Daemon Server" for the steps involved.
--
David B. White
IBM Microelectronics, Circuit Verification & Design Tools
Internal: dbwhite@btv Internet: dbwhite@vnet.ibm.com
Phone: 802-769-5671 (TieLine: 446) Fax: 802-769-5722
------------------------------
Date: Fri, 16 Oct 1998 17:07:41 GMT
From: w.wilson@mailexcite.com
Subject: Need help with this script
Message-Id: <707ugt$2ab$1@nnrp1.dejanews.com>
I'm writing this fairly simple script to get some input, open and lock a file
and write the input to the file. The major question I have is, is this a
decent way to do this (see script below)? Any guidance as to the best way to
accomplish this would be appreciated. Also, what am I doing wrong with my
array that it won't print to the file, and how do I know if the file is
locking? My flock implementation is stolen from the man pages, I really
couldn't find a decent example of how to use it...so I'm a little lost.
Thanks for the help.
P.S. sorry if this is _really_ hosed, I'm very new to this
Script;
#!/usr/local/bin/perl -w
$LOCK_EX = 2;
$LOCK_UN = 8;
print "Please enter your login name: ";
chomp($name = <STDIN>);
print "\nPlease enter some info about the change\n";
print "End input by typing ^D: ";
while(<STDIN>) {
until(\cD) {
@comment_array = <STDIN>;
}
}
open(LOG, ">>/tmp/blah") or die "Couldn't open file: $!";
&lock_file;
print LOG ('$' x 80), "\n";
print LOG "$name ", `date`;
print LOG ('$' x 80), "\n";
print LOG @comment_array;
&unlock_file;
close(LOG) or die "Can't close the file: $!";
# Subs
sub lock_file {
flock LOG, $LOCK_EX;
seek LOG, 0, 2;
}
sub unlock_file {
flock LOG, $LOCK_UN;
}
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 16 Oct 1998 10:29:59 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: newbie: getting the wrong month out of localtime()
Message-Id: <MPG.109122717359915698981b@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <362772ac.0@news.new-era.net> on 16 Oct 1998 16:22:04 GMT,
scott@softbase.com <scott@softbase.com> says...
> Marcel Duivesteijn (M.Duivesteijn@cao-horeca.nl) wrote:
> > To my surprise I got the wrong month. I got month 9 instead of 10.
>
> SURPRISE! Welcome to be brain-damaged world of UNIX and C time
> functions. The month is 0..11 instead of 1..12, which has to be one of
> the all-time boneheaded decisions in the history of computing. It
> started in UNIX, and the UNIX time libraries got codified as-is to
> become the ANSI C libraries. Perl uses these as-is. The brain damage
> is here to stay!
In some sense it is refreshing to see some Unix bashing here instead of
only Windows/DOS. If only you knew what you were talking about!
Tony Curtis (Tony.Curtis+usenet@vcpc.univie.ac.at) wrote:
!Tony> The month field goes from 0 .. 11 (presumably for the
!Tony> historic reason that C subscripts start at 0).
And so do Perl's (unless one messes with "$[", which is a no-no.)
!Scott> I wonder if this is the reason.
Of course that is the reason. For easy indexing into a name-string
array.
!Scott> The struct tm is not consistent
!Scott> if it is -- days of the month is 1..31, not 0..30.
When was the last time you used 'day of the month' as an array index?
!Scott> Day of the
!Scott> week is utterly, hopelessly confused. It goes from 0..7 on
!Scott> most of the UNIX systems I have access to, and no two seem to
!Scott> agree on it. So we have an 8 day week.
Utter nonsense. This is defined in the ANSI/ISO C Standard, section
4.12.1, as 0 .. 6. And all systemns agree. Maybe you are confusing
this with the 'date(1)' command, which lets you define Sunday as 0 or 7,
but not both.
Not that there aren't other errors or strangenesses. The range of
'seconds' is 0 .. 61 even though there can never be two leap seconds in
one minute and, using the Epoch time scale, there can never be any leap
seconds at all. And the 'day of the year' is 0 .. 365, though that
would never be used as an array index either.
But none of this really matters. The correct answer to the original
post is RTFM for `perldoc -f localtime`, if it doesn't seem to behave
the way you expect, not to post your silliness here.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 16 Oct 1998 12:33:46 -0500
From: Andrew Johnson <ajohnson@gatewest.net>
Subject: Re: Perl FAQ - error found in "#How_do_I_get_a_file_s_timestamp_"
Message-Id: <3627837A.99C566B@gatewest.net>
Craig Berry wrote:
!
! Daniel Grisinger (dgris@perrin.dimensional.com) wrote:
! : James Ludlow <ludlow@us.ibm.com> writes:
! : > Locally, I'm using version 5.004_02, and the error is in my copy of the
! : > FAQ also.
! :
! : So create a patch and send it to Tom. You obviously know the
! : solution, fix it.
! :
! : dgris
! : - Amazed at the fact that so many people use free software
! : but still don't get it.
!
! Not everyone knows how to do that. A pointer to doc on the topic
! would be more helpful than this unwarranted slam. (I'd provide said
! pointer, were I not among those who don't know.)
a useful starting place is the patching.pod document found under
the Porting directory of the source distribution, ie:
perl5.005_02/Porting/patching.pod
regards
andrew
------------------------------
Date: 16 Oct 1998 13:53:45 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: problem with "use lib"
Message-Id: <708179$4bp$1@monet.op.net>
In article <707kmr$ig0$1@nnrp1.dejanews.com>, <dturley@pobox.com> wrote:
>In article <7059hg$d05$1@csnews.cs.colorado.edu>,
> tchrist@mox.perl.com (Tom Christiansen) wrote:
>> In comp.lang.perl.misc, Randal Schwartz <merlyn@stonehenge.com> writes:
>> : use constant MY_LIB => /u/lib/perl;
>>
>> I think not.
>
>Okay, I'll bite. Perhaps a bit of explanation for the resrt of us. :-)
In Perl, the slash character delimits a regular expression or
indicates an arithmetic division operation.
It's just a nitpick. Randal forgot to quote the pathname.
------------------------------
Date: Fri, 16 Oct 1998 09:53:35 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Slow Sort?
Message-Id: <MPG.109119ea8fa53b7098981a@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <707pl6$s40@euphony.tri.sbc.com> on 16 Oct 1998 10:44:38 -
0500, Steve Monson <monson@tri.sbc.com> says...
...
> In fact, by checkpointing with time() before and after the sort, I
> got the stats (in seconds):
>
> 64 Compute average sentence length (one pass over the data)
> 2841 Sort sentence lengths
...
> Now, when I changed my code to use Unix's system sort on a file:
>
> open(OUT,">/tmp/sl"); foreach (@sl) {print OUT $_,"\n";} close(OUT);
The following is a *much* faster way of writing the temp file (more than
five times faster by my benchmark):
open(OUT,">/tmp/sl");
{ local $" = "\n"; print OUT "@s1\n" }
close(OUT);
> open(IN,"sort -rn /tmp/sl|"); @sl = <IN>; close(IN); chop @sl;
You *really* should check the results of those two 'open's :-).
> I got the following statistics, which seem more expected:
>
> 64 Compute average sentence length
> 5 Sort sentence lengths
>
> That is, Unix sorted in 5 seconds what took perl 40 minutes or more
> to sort. I've been happy with perl till now. Did I hit some kind of
> performance threshold?
>
> Flash: I just wrote a small 3-line perl program to fill a 102,000-
> element list with random numbers, and then sort it. It did it in 15
> seconds. So, I guess there's some memory-management problem with
> perl/unix interaction at work here.
The last time I looked into the Unix 'sort' command (and I doubt that it
has changed much since then), it used a sort-to-temp-files-and-merge
approach for data sets larger than a certain memory limit. On the other
hand, the Perl sort is a reworking of the C library function 'qsort',
which operates straightforwardly on an array, all of which must be in
memory (physical or virtual). So what you are seeing is undoubtedly the
thrashing of the swap file.
You can confirm this by measuring the actual CPU time used: put
my $t0 = (times)[0];
at the beginning of the sort and
my $t1 = (times)[0];
at the end, and subtract to get the CPU time (a floating-point number
whose units are seconds). It shouldn't be extraordinary.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 16 Oct 1998 17:23:11 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: Slow Sort?
Message-Id: <36277E7C.5FB200B@bbnplanet.com>
Larry Rosler wrote:
> The last time I looked into the Unix 'sort' command (and I doubt that it
> has changed much since then), it used a sort-to-temp-files-and-merge
> approach for data sets larger than a certain memory limit. On the other
> hand, the Perl sort is a reworking of the C library function 'qsort',
> which operates straightforwardly on an array, all of which must be in
> memory (physical or virtual). So what you are seeing is undoubtedly the
> thrashing of the swap file.
Yeah, but, Larry, 40 Minutes???? I gotta see this code. My sparc5
thrashes when I do a sort with 64mb, but with large arrays I've never
seen 40 minutes. And as far as I know, the last time I saw the Solaris
source, sort hasn't really changed much over the years.
e.
After all, the cultivated person's first duty is to
always be prepared to rewrite the encyclopedia. - U. Eco -
------------------------------
Date: Fri, 16 Oct 1998 18:48:13 +0100
From: Matt Pryor <matt@whiterabbit.co.uk>
To: Steve Monson <monson@tri.sbc.com>
Subject: Re: Slow Sort?
Message-Id: <362786DD.84666742@whiterabbit.co.uk>
The sort function in this code:
srand;
foreach(0..102000) {
$x[$_]=int(rand(time)*100);
print "." if ($_/1000 eq int($_/1000));
}
print "\nSorting...\n";
$t = time;
@sorted = sort {$b<=>$a} @x; # There's the culprit!
$t = time-$t;
print "Done in $t seconds.\n";
exit(0);
Took just 9 seconds under Win95 with a Cyrix 200mhz processor with 32
meg ram...
Matt
--
Steve Monson wrote:
>
> In the course of doing a little statistical analysis, I found a need
> to sort a list I'd built up. Just a straight numeric sort, in
> descending order, which I did as
>
> @sl = sort {$b <=> $a} @sl;
>
> All well and good. As it happened, the array contained about 102,000
> elements. The execution time was 40, that's right, 40 *minutes*, that's
> right, minutes, not seconds.
>
> Now, the program was running on a SparcStation 20, with 64MB of RAM,
> and when I watched the program using "top" it indicated that about
> 28 MB of ram was being used, with 22MB resident. So, I expect that the
> sort was done in memory.
>
> In fact, by checkpointing with time() before and after the sort, I
> got the stats (in seconds):
>
> 64 Compute average sentence length (one pass over the data)
> 2841 Sort sentence lengths
>
> 102,000 elements is not trivial, but it's not such a huge number, either.
>
> Now, when I changed my code to use Unix's system sort on a file:
>
> open(OUT,">/tmp/sl"); foreach (@sl) {print OUT $_,"\n";} close(OUT);
> open(IN,"sort -rn /tmp/sl|"); @sl = <IN>; close(IN); chop @sl;
>
> I got the following statistics, which seem more expected:
>
> 64 Compute average sentence length
> 5 Sort sentence lengths
>
> That is, Unix sorted in 5 seconds what took perl 40 minutes or more
> to sort. I've been happy with perl till now. Did I hit some kind of
> performance threshold?
>
> Flash: I just wrote a small 3-line perl program to fill a 102,000-
> element list with random numbers, and then sort it. It did it in 15
> seconds. So, I guess there's some memory-management problem with
> perl/unix interaction at work here.
>
> Anyone else run into such a symptom?
>
> Steve Monson
> --
> I am a demolitions expert. If you see me running, try and keep up.
--
Matt's daily comic strip
Porridge and Fartcakes
http://www.whiterabbit.co.uk/cartoons
------------------------------
Date: Fri, 16 Oct 1998 17:59:44 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: Slow Sort?
Message-Id: <3627870C.2EE90AFD@bbnplanet.com>
Matt Pryor wrote:
> Took just 9 seconds under Win95 with a Cyrix 200mhz processor with 32
> meg ram...
10 seconds on Sparc5, 2.6, 64mb and while it was swapping like a maddog.
I want to see this 40 minute code! :)
e.
After all, the cultivated person's first duty is to
always be prepared to rewrite the encyclopedia. - U. Eco -
------------------------------
Date: 16 Oct 1998 13:06:22 -0400
From: Matt Curtin <cmcurtin@interhack.net>
Subject: Re: Sorry
Message-Id: <xlxvhlkl9m9.fsf@gold.cis.ohio-state.edu>
larry@kiev.wall.org (Larry Wall) writes:
> I intended you to take it however you like. :-)
Even Larry's English is late-typing. :-)
You gotta love it.
--
Matt Curtin cmcurtin@interhack.net http://www.interhack.net/people/cmcurtin/
------------------------------
Date: Fri, 16 Oct 1998 13:24:05 -0400
From: John Porter <jdporter@min.net>
Subject: Re: sorting
Message-Id: <36278135.9EFDBE84@min.net>
Uri Guttman wrote:
>
> i like this approach but it may be very slow.
No "may be" about it!
> # indicate how each field should be compared:
> my %field_to_compare_code = (
> age => '$a->{age} <=> $b->{age}',
> name => '$a->{name} cmp $b->{name}',
> );
I would start with a hash like mine, and generate the
hash like yours programmatically:
my %Fcmp = (
age => '<=>',
name => 'cmp',
);
my %field_to_compare_code = map {
$_ => "\$a->{$_} $Fcmp{$_} \$b->{$_}"
} keys %Fcmp;
> # list the fields by which the user wants to sort, in order:
> my $sort_sub = &build_sort_sub( 'age', 'name' );
>
> # do the sort:
> my @output = sort $sort_sub @input
My perl (5.004_04) complains that $sort_sub is not a GLOB ref.
This fixes it:
my @output = sort( *sort_sub, @input );
--
John "Gashlycrumb" Porter
"A fugitive and lurid gleam
Obliquely gilds the gliding stream." -- EG
------------------------------
Date: 16 Oct 1998 13:30:02 -0400
From: Uri Guttman <uri@camel.fastserv.com>
Subject: Re: sorting
Message-Id: <sarbtncpg85.fsf@camel.fastserv.com>
>>>>> "JP" == John Porter <jdporter@min.net> writes:
JP> Uri Guttman wrote:
JP> I would start with a hash like mine, and generate the
JP> hash like yours programmatically:
JP> my %Fcmp = (
JP> age => '<=>',
JP> name => 'cmp',
JP> );
JP> my %field_to_compare_code = map {
JP> $_ => "\$a->{$_} $Fcmp{$_} \$b->{$_}"
JP> } keys %Fcmp;
TMTOWTDI
is some cases the actual code may be better to use since it may be more
complex than a hash lookup. depending on the sort field you might need
to do more work. so your opcode hash is more limited in its flexibility.
>> my @output = sort $sort_sub @input
JP> My perl (5.004_04) complains that $sort_sub is not a GLOB ref.
JP> This fixes it:
JP> my @output = sort( *sort_sub, @input );
as i said i didn't test it, i just invented it. :-)
&{$sort_sub} should work too.
uri
--
Uri Guttman Fast Engines -- The Leader in Fast CGI Technology
uri@fastengines.com http://www.fastengines.com
------------------------------
Date: Fri, 16 Oct 1998 11:56:37 -0500
From: Stephen Palmer <slpalmer@NOSPAM.flex.net>
Subject: SUMMARY: Perl5 on Solaris reading MS Access Database
Message-Id: <36277AC5.72B99329@NOSPAM.flex.net>
Thanks to all for the responses you've sent.
Quick summary of information I've received so far:
==== My original question ====
Stephen Palmer (slpalmer@NOSPAM.flex.net) wrote:
> After a careful search of DejaNews, and CPAN, I'm still at a loss as to
> how to read from a MS Access Database using perl 5.04. I would
> appreciate responses from anyone who has succeded in doing this (from
> Perl on UNIX). I saw through DejaNews that several others have asked
> this, and some succeded (under Win32) but I have not seen a summary of
> how to do it from a UNIX host. I will be glad to post such a summary if
> I manage to do this. :-)
==== Solution ====
Tim Haynes wrote:
Hi,
Just as a direct pointer, OpenLink will connect your perl programs to Access;
the drivers (ODBC, UDBC and JDBC) are available for free evaluation download
from <http://www.openlinksw.com/> onwards.
Best regards,
Tim Haynes
Support Consultant
OpenLink Software Web: <http://www.openlinksw.co.uk/>
Universal Database Connectivity Technology Providers
==== Reasoning why I don't want to do this ====
scott@softbase.com wrote:
There is no good way to do this, because Access doesn't work in a
networked environment. Access is also not a multiuser database like
Oracle or DB2 and can't support multiple users on the same database. It
has some primitive multiuser capabilities that work only with
NetBEUI-style Microsoft networking.
The only way I know that you could possibly do this is to write a
TCP/IP server which reads SQL text over the network, and runs it
against the database, and sends the results back. I've never heard of
anyone writing this.
The general problems are:
1) Access is not designed to do what you want to do, and
any solution will be less than optimal. It'll be an
ugly hack. For example, even if you paid a lot of money
for an ODBC implementation on UNIX, Access has no
networking capabilities, so it wouldn't do you any
good. The only thing you can do is write your own
middleware layer and duplicate things like
DB2 connect. Access has nothing like this itself, because
it is not networkable. Even if you got it to work, the
solution would be highly limited because concurrent
access to databases would be lacking.
2) You're trying to go from a server to a client, which
is bassackwards. There's no good support for this, because
it is unnatural. Going from a client to a server is the
way 99.44% of people do it, and the other .56% of the time
the solution is either unsolved because not enough people
do it to make it worth doing, not able to be solved as in
the case of Access, or so expensive it wouldn't matter.
Scott
--
---
Stephen L. Palmer
Email aistslp@NOSPAM.sugarland.se76.com
Email slpalmer@NOSPAM.sprintparanet.com
Pager (800)724-3329 or slpalmer@NOSPAM.pager.sprintparanet.com
PIN 382-1266 (Short msgs please)
Remove anti-spam info before sending.
------------------------------
Date: Fri, 16 Oct 1998 11:58:16 -0500
From: Tk Soh <r28629@email.sps.mot.com>
To: Larry Rosler <lr@hpl.hp.com>
Subject: Re: The space deletion woes...
Message-Id: <36277B28.7D16E4C@email.sps.mot.com>
Larry Rosler wrote:
> #!/usr/local/bin/perl -w
> use Benchmark;
>
> $x = ' Here goes nothing one space now ';
>
> timethese (1 << (shift || 0), {
> All => sub { $_ = $x; s/\s+//g },
> One => sub { $_ = $x; s/\s+?//g },
> } );
>
> Benchmark: timing 65536 iterations of All, One...
> All: 3 wallclock secs ( 3.69 usr + 0.00 sys = 3.69 CPU)
> One: 5 wallclock secs ( 5.20 usr + 0.00 sys = 5.20 CPU)
>
Would tr///d be a better choice?
#!/usr/local/bin/perl -w
use Benchmark;
$x = " Here goes nothing one space now\t\fend\nhere";
timethese (50000, {
All => sub { $_ = $x; s/\s+//g },
One => sub { $_ = $x; s/\s+?//g },
tr=> sub { $_ = $x; tr/ \t\n\r\f//d},
} );
Benchmark: timing 50000 iterations of All, One, tr...
All: 8 wallclock secs ( 7.11 usr + 0.00 sys = 7.11 CPU)
One: 11 wallclock secs (10.67 usr + 0.00 sys = 10.67 CPU)
tr: 3 wallclock secs ( 2.81 usr + 0.00 sys = 2.81 CPU)
------------------------------
Date: Fri, 16 Oct 1998 17:52:40 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: The space deletion woes...
Message-Id: <36278565.53871A11@bbnplanet.com>
Tk Soh wrote:
> Benchmark: timing 50000 iterations of All, One, tr...
> All: 8 wallclock secs ( 7.11 usr + 0.00 sys = 7.11 CPU)
> One: 11 wallclock secs (10.67 usr + 0.00 sys = 10.67 CPU)
> tr: 3 wallclock secs ( 2.81 usr + 0.00 sys = 2.81 CPU)
Hmmmm. Why is this so much faster? Larry? And would it work as
advertised in all cases?
e.
After all, the cultivated person's first duty is to
always be prepared to rewrite the encyclopedia. - U. Eco -
------------------------------
Date: 16 Oct 1998 17:13:22 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Using a variable in a grep search
Message-Id: <707uri$q8d$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, cheeze-whiz@usa.net (The Cheeze Whiz) writes:
:I'm trying to write a script that performs a grep search of a file and
:allows users to specify the search term. The problem I'm facing is that
:'$' is a regular expression pattern and escaping the $ looks for '$'
:(rather than parsing the perl variable).
:
:For example:
:
1: print "Enter the search term:";
2: $input = <STDIN>;
3: open(MYFILE,"myfile");
4: @myfile = <MYFILE>;
5: close MYFILE;
6:-> @results = grep (/$input/, @myfile);
7: print "$results[0]\n";
:
:
:What's the trick?
Well, you have many problems of varying degrees, and on
virtualyl every line.
Line 1: This one is ok, although I would put a space
after the colon, personally. You might also
suppress the prompt if not running interactively.
Line 2: You read a line, but neglected to check whether it
was a successful (defined) read operation. Secondly,
you didn't chomp the newline -- this is the thing
that is likely biting you most. Thirdly, you didn't
check whether the resulting string was of zero length.
Line 3: You opened the file, but forgot to check the return
value and print the proper system error message.
Line 4: Why are you reading the while file into memory at once
before you check for something? You should check
incrementally to save memory.
Line 5: You did a system call and neglected its return value again.
Line 6: You didn't use a /o, but your search pattern appears
invariant? In one sample test, using /o here speeds the
match by 25%. Of course, this usually won't work at all
because you didn't chomp the newline earlier.
Line 7: If you got no hits, then you are using an undefined value here
where you need a real one. That means that -w will give you
warnings. Also, did you really read the whole file into memory
(which takes far more memory than you would imagine) and then
compare each and every line in that array to a pattern --
merely to get at the first successful match? If so, you have
wasted a tremendous amount of energy.
Remember that grep in perl is just this:
die "usage: $0 pattern [files ...]\n" unless @ARGV:
$pat = shift;
while (<>) {
print if /$pat/o;
}
Or minimally,
$pat = shift or die "usage";
/$pat/o && print while <>;
Notice that you don't prompt the user -- you read the pattern
from the command line, and then process @ARGV for input files.
All this prompting is very odd.
But following your template, I might have written something
more like this:
do {
print "Enter the search term: " if -t STDIN && -t STDOUT;
$input = <STDIN>;
defined $input or exit 1;
for ($input) {
s/^\s+//;
s/\s+$//;
}
} until length $input;
open(MYFILE, "myfile") or die "can't open myfile: $!";
while (<MYFILE>) {
if (/$input/o) {
print;
last;
}
}
close MYFILE or die "can't close myfile: $!";
Notes:
1) The results of the interactivity test should probably be cached in
a variable.
2) The premature exit from the loop and then the close would not
necessarily have worked properly if you were reading from a child
process who wasn't done feeding you.
--tom
--
It's there as a sop to former Ada programmers. :-)
--Larry Wall regarding 10_000_000 in <11556@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: 12 Jul 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 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 3993
**************************************