[21887] in Perl-Users-Digest
Perl-Users Digest, Issue: 4091 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 9 18:06:37 2002
Date: Sat, 9 Nov 2002 15:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 9 Nov 2002 Volume: 10 Number: 4091
Today's topics:
[OT] Leaffoot, the beer is not free. <billwheaton@mindspring.com>
AxKit not returning any output <ngroups@ians-netNOSPAM.co.uk>
Can you Simplify My Code #2? <member@mainframeforum.com>
Re: Can you Simplify My Code #2? <tassilo.parseval@post.rwth-aachen.de>
Re: Can you Simplify My Code #2? (Tad McClellan)
Re: Can you Simplify My Code #2? <pinyaj@rpi.edu>
Can you Simplify My Code? <member@mainframeforum.com>
Re: Can you Simplify My Code? <jurgenex@hotmail.com>
change text colour? <mail@eircom.net>
Re: change text colour? <tk@WINDOZEdigiserv.net>
Function call inside Quotes? <member@mainframeforum.com>
Re: Function call inside Quotes? (Tad McClellan)
Re: Memory Usage When Reading Large (non crlf) Files (CK)
Re: Pause in perl ??? <bdonlan@users.sf.net>
Re: Pause in perl ??? <mail@eircom.net>
Re: Pause in perl ??? <mail@eircom.net>
PHP extranet file archive recommendation (Hobichu)
Proper pipe handling <nospam@hooey.invalid>
randomizing results from a mysql database (kramer)
Re: Safest way to convert $d.cc to $DCC ? <kirkspam@alienbill.com>
Re: significance of 42 for perl, any?!? <billwheaton@mindspring.com>
Re: Simple, almost stupid question! (Tad McClellan)
Re: Simple, almost stupid question! <wksmith@optonline.net>
Re: wish fast method of counting of characters <krahnj@acm.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 9 Nov 2002 15:09:09 -0500
From: "Bill Wheaton" <billwheaton@mindspring.com>
Subject: [OT] Leaffoot, the beer is not free.
Message-Id: <aqjrgn$4nl$1@slb5.atl.mindspring.net>
Leaffoot,
You said "Wow, sometimes I can't believe this kind of code help is free."
I've seen this light-bulb turn on before, so this is not really directed
solely at you, but merely your sentiment generally. My hope is that new
people reading this may get a my flavor of some common sentiments, and
perhaps even discover that Perl programmers have a lot more invested than
mere programming. If not, I hope you enjoy seeing your name as a subject
line associated with beer, as I couldn't justify a direct response in the
other thread. Either way, some of it is just flat not aimed at you at all.
I am not at the point in my career where sharing my perl with others is a
good idea. While what I do borders on the elegant, but so many things I do
will lead others astray. That aside, I think I understand the 'free' thing,
so until I can give back in kind, I will give back this. On with my
diatribe.
-----
Free?
Its not free.
There is the cost of the computer you type the message on.
There is the cost your employer pays you for having the intelligence and
initiative to come here.
There is the cost of the connection to the internet, paid for by magnanimous
donations to universities by people who appreciated where they got their
money and gave some back, forward looking companies and taxing yet
egalitarian governments.
There is the cost of individuals who donate their time to render the help,
because they have been helped before.
This list goes on; no, its not free, its different.
I am so glad that you are excited. It shows that you are throwing away that
mantle of secrecy cast by the Borg Collective in Redmond. It shows that
that you may be open to those that cast doubt on efficacy of a whole world
drinking the 'Real Thing' or arguing over 'Tastes great, Less filling' while
ending up with a substance filtered through a horses urinary tract. Perhaps
when you do your Christmas shopping, you will patronize local businesses and
stay away from BarnesAndNoble.com, Wallmart and 'The Mall'?
My heart soars at the prospect, so my question is this:
What will you do, now that you know, to defray the costs?
Once, an unemployed member of our gang of former high school mates was low
on cash, but we did the right thing, (even before it was properly
proper-cased). After a typical night of swilling beer at our local,
politically active pub, we covered his tab. We did this a lot for each
other, because somebody was always looking for work in those days. We
simply couldn't rationalize unemployment as a valid reason for abstaining
from what Benjamin Franklin considered a gift from God -- a pint or two (or
three or four) of good, wholesome ale. After a while, we came to realize
that though he now had a job, he still claimed indigence and did not follow
our sacred tradition and duty in regard to alms.
Its been twenty-seven years now, Jim's married with two kids, as is Dave,
Frank moved to Mississippi, but comes back a lot, Steve got married,
divorced, and remarried, Brad's still an asshole, but lovable as ever, and
we still go down to Manual's Tavern now and then or to baseball and hockey
games. We've all dated each others sisters, and eventually married our own
sweethearts, who themselves have become friends. Each year we get together
for Christmas at the very least and shower their kids with presents.
We tip our publicans here in the States, anachronistic as it seems (we also
use inches and gallons which puts us miles ahead when it comes to binary
arithmetic!). Perhaps when someone saw our buddy grabbing the tip on more
than one occasion made our eyes roll, I don't know. Whats-his-name's name
totally escapes me now. We were all roommates at one point or another.
C'est la vie.
So, you see, when someone says "Its free, as in 'freedom', not as in 'free
beer'", they are oh so wrong, because even free beer is not free, there is
cost involved, and worth immeasurable.
When _this_ beer keg is tapped, you are expected to have as many pints as
you want, so long as you don't get too drunk too often. You are expected to
pour a glass for someone else. You are expected to raise a glass and toast
in honor of those who have gone before. We show respect by exhaustive
searches of the faqs and documentation, and we write perl when we mean
'perl', Perl when we mean 'Perl', but never PERL, pearl, or Gloria. We take
to heart, help rendered and strive to understand and improve our craft and
handiwork. At times we humble and at other times we are humbled. If
internalized, it is then also understood that the true cost is the true
worth and that comes from the giving. Without the giving, there would be no
Perl.
In the United States, when our hearts were still numb, a former Texas State
governor, asked in his first 'State of the Union Address' for all Americans
to render two years of service to our country. Perhaps in your countries,
your leaders have asked the same of ya'll. In so doing, you can say that
you are patriotic. This sort of common patriotism is the Right Thing. But
this is an international forum that predates even GWB's residency. We've
been doing this for a while, and we express our service and patriotism, not
only to our individual countries, but to all of them. And we don't do it
for 4000 hours, we do it until we are done, and we expect the same of others
and for all to contribute and pull their weight. George's pep talk wasn't a
Bad Idea, as far as it went.
One way to pull your weight is to ask intelligent questions. In this way,
others who are able, can exercise their minds and answer you. It will spark
ideas in your mind and the minds of others. Another way is to provide
answers, and to temperately rebuke the tyro. In that way, the thoughtful
newcomer can gauge acceptable manners and discourse.
I revel in the differences between us, even the sometimes sharp words used.
So another way to contribute, sometimes, is with sharp words. My cat will
never jump up on our gas stove again, I can tell you that much. Sometimes
the differences are because we come from different countries, and that
Americans tend to think that everyone else on forums is just like them,
Americans wearing different clothes. Often we Americans forget our manners
that way. When we are brought to our senses, sometimes with truly stinging
rants, we learn, but usually only individually. So another way to
contribute, is to be empathetic and cop a 'viva le differance' attitude. I
think it is sad that so much of the world is adopting American ways at the
expense of their own, willingly or not. Free trade is great and everything,
but we don't have to export Americana, just our goods; remembering that
there are four winds, not one.
There is a cost to not recognizing our roles; it is not free. Everyone,
everywhere will be drinking Bud-Lite, and the so-called American 'melting
pot' will host a cold, fine slurry of gruel, covered in goop. If I could
send every American to a party full of Brits, Canadians, Frenchmen,
Germans... but I stray. That's like a cat saying "Thumbs! If only I had
opposable thumbs!".
Did I mention I brew beer? I love beer quotes, here is one:
"What makes your heart feel wonderful, makes also our heart feel wonderful.
Our liver is happy, our heart is joyful. May Ninkasi live together with
you."
-a hymn to Ninkasi, Goddess of beer. Sumeria, 1800 bce.
So you bring the barley malt, and you there draw some water, I'll get the
hops, and we'll toss it all into this, our lauter-tun. With time we'll have
beer, and it will be fresh and all our own. I'm not sure what the Sumerians
meant, but since the hymn was accompanied by a recipe for beer, and it is a
hymn presumably sung by a group, I can only assume that its always been
known that a fulfilled life can come from openly working together, fairly
giving and fairly taking in balance.
But there is a cost. Always a cost. Buried deep down in the ground
somewhere is where the cost of freedom may be found. If you like the idea,
"... Lay your body down." Others have. Perhaps this is why "...this kind
of code help" is the way it is.
Bill Wheaton
Atlanta, GA USA
------------------------------
Date: Sat, 09 Nov 2002 19:10:28 +0000
From: Ian Gregory <ngroups@ians-netNOSPAM.co.uk>
Subject: AxKit not returning any output
Message-Id: <aqjmmp$h24$2@godfrey.mcc.ac.uk>
Hi there,
Apologies if this isn't the ideal place to post this message - my mails
are bouncing from the axkit mailing list.
I've installed Axkit on OpenBSD 3.2 from the port on
http://archives.neohapsis.com/archives/openbsd/2002-08/0504.html
However, when I request a page that is processed through
AxKit, the connection is closed before any data is sent:
bash# GET http://127.0.0.1/xml/test.xml
<HTML>
<HEAD><TITLE>An Error Occurred</TITLE></HEAD>
<BODY>
<H1>An Error Occurred</H1>
500 EOF instead of reponse status line
</BODY>
</HTML>
The Apache error log shows:
[Sat Nov 9 18:40:02 2002] [warn] [client 127.0.0.1] [AxKit] handler
called for /xml/test.xml
[Sat Nov 9 18:40:02 2002] [warn] [client 127.0.0.1] [AxKit] checking if
we process this resource
[Sat Nov 9 18:40:02 2002] [warn] [client 127.0.0.1] [AxKit] media:
screen, preferred style: #default
[Sat Nov 9 18:40:02 2002] [warn] [client 127.0.0.1] [AxKit] Cache: key
= c19cc1ed2723e4a0933e9352cc41de5d
[Sat Nov 9 18:40:02 2002] [warn] [client 127.0.0.1] [AxKit] getting
styles and external entities from the XML
[Sat Nov 9 18:40:02 2002] [warn] [client 127.0.0.1] [AxKit] styles not
cached - calling $provider->get_styles()
[Sat Nov 9 18:40:02 2002] [warn] [client 127.0.0.1] [AxKit] using XS
get_styles (libxml2)
[Sat Nov 9 18:40:02 2002] [warn] [client 127.0.0.1] [AxKit] calling
xs_get_styles_fh()
It ends there. The relevant bit of my httpd.conf is:
##
## AxKit Configuration
##
PerlModule AxKit
<Directory "/var/www/htdocs/xml/">
Options -All +Indexes +FollowSymLinks
# Tell mod_dir to translate / to /index.xml or /index.xsp
DirectoryIndex index.xsp
AddHandler axkit .xml .xsp
AxDebugLevel 10
AxGzipOutput On
AxAddXSPTaglib AxKit::XSP::Util
AxAddStyleMap application/x-xsp \
Apache::AxKit::Language::XSP
</Directory>
Does anyone have any suggestions? I've tried recompiling apache (without
expat) and mod_perl but with no sucess...
Cheers,
--
Ian
http://www.ians-net.co.uk
------------------------------
Date: 9 Nov 2002 15:16:04 -0500
From: yisraelharris <member@mainframeforum.com>
Subject: Can you Simplify My Code #2?
Message-Id: <3dcd6d04$1_8@news.onlynews.com>
Is there any way to simplify the 3 statements of code inside the while
loop into 1 or 2 statements?
while (my @ary = $sth->fetchrow_array) { my %row_data;
$row_data{SPECIALTY} = "$ary[0]"; push(@loop_data,
\%row_data); }
Thanks.
--
www.MainFrameForum.com - USENET Gateway
------------------------------
Date: 9 Nov 2002 21:03:48 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Can you Simplify My Code #2?
Message-Id: <aqjt7k$9n5$1@nets3.rz.RWTH-Aachen.DE>
Also sprach yisraelharris:
> Is there any way to simplify the 3 statements of code inside the while
> loop into 1 or 2 statements?
>
> while (my @ary = $sth->fetchrow_array) { my %row_data;
> $row_data{SPECIALTY} = "$ary[0]"; push(@loop_data,
> \%row_data); }
Yes, there is:
while (my @ary = $sth->fetchrow_array) {
push @loop_data, { SPECIALITY => $ary[0] };
}
This pushes a reference to an anonymous hash created on the fly onto
@loop_data.
As a side note: You seem to be very concerned with making your Perl-code
as short as possible (see your other thread). Why is it that important
to you? Choose the most readable solution, not the shortest one. In this
case a short one happens to be readable, but this is not always the
case.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Sat, 9 Nov 2002 15:17:21 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Can you Simplify My Code #2?
Message-Id: <slrnasqur1.2lo.tadmc@magna.augustmail.com>
yisraelharris <member@mainframeforum.com> wrote:
> Is there any way to simplify the 3 statements of code inside the while
> loop into 1 or 2 statements?
>
> while (my @ary = $sth->fetchrow_array) { my %row_data;
> $row_data{SPECIALTY} = "$ary[0]"; push(@loop_data,
^ ^
Those quotes don't do anything (useful), so they should not be there.
> \%row_data); }
You can use an anonymous hash rather than a named hash:
while (my @ary = $sth->fetchrow_array) {
push @loop_data, { SPECIALTY => $ary[0] };
}
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 9 Nov 2002 17:08:29 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: yisraelharris <member@mainframeforum.com>
Subject: Re: Can you Simplify My Code #2?
Message-Id: <Pine.A41.3.96.1021109170731.22498A-100000@vcmr-104.server.rpi.edu>
[posted & mailed]
On 9 Nov 2002, yisraelharris wrote:
>Is there any way to simplify the 3 statements of code inside the while
>loop into 1 or 2 statements?
>
> while (my @ary = $sth->fetchrow_array) { my %row_data;
> $row_data{SPECIALTY} = "$ary[0]"; push(@loop_data,
> \%row_data); }
If you only need the first value, I'd do:
while (my($v) = $sth->fetchrow_array) {
push @loop_data, { SPECIALITY => $v };
}
--
Jeff "japhy" Pinyan RPI Acacia Brother #734 2002 Acacia Senior Dean
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: 9 Nov 2002 15:16:03 -0500
From: yisraelharris <member@mainframeforum.com>
Subject: Can you Simplify My Code?
Message-Id: <3dcd6d03$1_8@news.onlynews.com>
The following function strips away trailing blanks. What I'm wondering
is whether it can be simplified?
sub trimBlanks { my $string = $_[0]; $string =~ s/ *$//; return
$string; }
The direction I'm looking for is a one-line statement that says: return
the parameter sent, only substitute all trailing blanks with nothing. I
am new to Perl and am wondering if its syntax allows this sort of thing.
Thanks.
--
www.MainFrameForum.com - USENET Gateway
------------------------------
Date: Sat, 09 Nov 2002 20:53:59 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Can you Simplify My Code?
Message-Id: <HBez9.10289$Dl.7582@nwrddc01.gnilink.net>
yisraelharris wrote:
> The following function strips away trailing blanks. What I'm wondering
> is whether it can be simplified?
>
> sub trimBlanks { my $string = $_[0]; $string =~ s/ *$//; return
> $string; }
>
> The direction I'm looking for is a one-line statement that says:
> return the parameter sent, only substitute all trailing blanks with
> nothing. I am new to Perl and am wondering if its syntax allows this
> sort of thing.
Did you check the answer to FAQ
"How do I strip blank space from the beginning/end of a string?"
jue
------------------------------
Date: Sat, 9 Nov 2002 22:16:48 -0800
From: "Linux.ie" <mail@eircom.net>
Subject: change text colour?
Message-Id: <aqjtq1$rha$1@dorito.esatclear.ie>
is it possilbe to change the colour of the text in ms-dos to green ???
------------------------------
Date: Sat, 09 Nov 2002 22:29:25 GMT
From: tk <tk@WINDOZEdigiserv.net>
Subject: Re: change text colour?
Message-Id: <433rsucps00i14kcpqirdaec7btbpfic43@4ax.com>
In a fit of excitement on Sat, 9 Nov 2002 22:16:48 -0800, "Linux.ie"
<mail@eircom.net> managed to scribble:
| is it possilbe to change the colour of the text in ms-dos to green ???
|
And this relates to Perl in what way?
tk
--
+--------------------------+
| digiServ Network |
| Web solutions |
| http://www.digiserv.net/ |
+--------------------------+
Remove WINDOZE to reply
------------------------------
Date: 9 Nov 2002 15:16:04 -0500
From: yisraelharris <member@mainframeforum.com>
Subject: Function call inside Quotes?
Message-Id: <3dcd6d04$3_8@news.onlynews.com>
In situations like this:
my $word = "some text " . length($y) . " more text"; # 1 syntax
Obviously, if I do the following, I won't be the same as in #1 above:
my $word = "some text length($y) more text"; # 2 syntax
My question is: Is there some way to use the #2 syntax, with maybe some
special character before the call to length, so that perl knows to treat
it as a function call, as in #1? Or do I have to stick to #1?
Thanks.
--
www.MainFrameForum.com - USENET Gateway
------------------------------
Date: Sat, 9 Nov 2002 15:19:48 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Function call inside Quotes?
Message-Id: <slrnasquvk.2lo.tadmc@magna.augustmail.com>
yisraelharris <member@mainframeforum.com> wrote:
> my $word = "some text length($y) more text"; # 2 syntax
>
> My question is:
Frequently Asked.
You should check the Perl FAQ *before* posting to the Perl newsgroup.
> so that perl knows to treat
> it as a function call
^^^^^^^^
perldoc -q function
"How do I expand function calls in a string?"
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 9 Nov 2002 12:42:44 -0800
From: fw58959@hotmail.com (CK)
Subject: Re: Memory Usage When Reading Large (non crlf) Files
Message-Id: <c0367340.0211091242.ed77c45@posting.google.com>
Brian McCauley <nobull@mail.com> wrote in message news:<u93cqb5062.fsf@wcl-l.bham.ac.uk>...
> fw58959@hotmail.com (CK) writes:
>
> > for (1..$count) { # decode each subrecord and print it to another
>
> How big is $count? It it is big then consider: Does the version of
> Perl you are using postdate the version where that is optomized? ( I
> can't recall when that was).
>
> Try :
>
> perl -e 'for ( 1 .. 100000000 ) { print; last; }'
>
> If it prints "1" immediately the you are OK.
>
> If it prints "Out of memory!" then try changing your program to use a
> C-style for() or get a recent version of Perl.
>
> If $count is not big then you have a memory leak. Memory leaks are
> not uncommon in Perl.
>
> > A snippet of the code follows:
>
> In situations like this a snippet is not helpfull. It is quite likely
> the problem is not in what you chose show us.
>
> Always produce a _minimal_ but _complete_ (strict, warning free)
> script that you have _actually_run_ and found to reproduce the
> problem. Post it in its entirity unaltered. Include mention of what
> version of Perl you are using.
Thank you for the reply.
It appears I am running version 5.005_03 of perl.
$count is never bigger than 30.
The perl -e 'for ( 1 .. 100000000 ) { print; last; }' returns 1
immediately.
I will try getting a more recent version to see if that makes a
difference. By posting the snippet I was seeing if anyone had seen a
problem with memory in a similar program structure. I didn't want to
scare someone off by posting a large chunk of code. I will look into
doing as you suggest if a newer version of perl doesn't help.
Thanks again for taking the time to comment.
./CK
------------------------------
Date: Sat, 09 Nov 2002 20:24:29 GMT
From: bd <bdonlan@users.sf.net>
Subject: Re: Pause in perl ???
Message-Id: <krqjqa-k4h.ln@ID-151211.user.cis.dfn.de>
Linux.ie wrote:
> Thanks guys.And David K.Wall its not homework. IAM ONLY 14 years old. i
> dont go to a Computer Science School !!!!
I'm only 14 years old and I didn't have any trouble figuring otu the answers
on my own. Try searching for a 'perl tutorial' on google, or buying a perl
book.
--
Never underestimate the power of human stupidity.
------------------------------
Date: Sat, 9 Nov 2002 21:35:54 -0800
From: "Linux.ie" <mail@eircom.net>
Subject: Re: Pause in perl ???
Message-Id: <aqjrdd$qk9$1@dorito.esatclear.ie>
yea, i got a book, but didnt bother reading it !!!
------------------------------
Date: Sat, 9 Nov 2002 21:36:45 -0800
From: "Linux.ie" <mail@eircom.net>
Subject: Re: Pause in perl ???
Message-Id: <aqjrev$qkb$1@dorito.esatclear.ie>
bd where abouts do you live. what country ??
------------------------------
Date: 9 Nov 2002 11:20:59 -0800
From: hobichu@netzero.net (Hobichu)
Subject: PHP extranet file archive recommendation
Message-Id: <51b3c916.0211091120.2a278f54@posting.google.com>
I am looking for a Web-based document archive software that allows:
- Upload/download/view files
- Creation of (sub-)folders
- delete/overwrite files; delete folders
- Folder-level ACLs (groups/users) and/or restriction of users to certain folders
And in addition:
- Stable
- Nice GUI; easy admin
- If RDBMS required, then MySQL based
Any recommendations?
------------------------------
Date: Sat, 09 Nov 2002 20:27:46 GMT
From: Starling <nospam@hooey.invalid>
Subject: Proper pipe handling
Message-Id: <m1vg36sfvj.fsf@localhost.localdomain>
--=-=-=
If someone could help me with this I'd really appreciate it. I'm
trying to learn how to work with pipes and forks in perl, and have
been getting intermittent errors. When I run the following program
without the debug flag, it works (so far...). When I run it with the
-d flag, it doesn't work, usually, but sometimes manages to spit out
the data before silently exiting. I know I must be doing something
wrong, but am not sure where my logic falls short of the truth.
--=-=-=
Content-Disposition: attachment; filename=test.pl
Content-Description: A test script with pipes, forks and problems.
#!/usr/bin/env bash
ulimit -c 0;
perl -d -x $0 $*;
exit;
#!perl
use POSIX ":sys_wait_h";
$SIG{'CHLD'} = \&Reaper;
$SIG{'PIPE'} = sub { Plumber("root") };
sub Plumber {
die join(', ', (shift, " pipe broke."));
}
sub Reaper {
my $child;
while(($child = waitpid(-1, &WNOHANG)) > 0) {
$Kid_Status{$child} = $?;
}
$SIG{CHLD} = \&Reaper;
}
$bkup_list="dest/list";
print "List generated. Starting archival process.\n";
pipe $brdr, $bwtr;
unless($cpiopid = fork)
{
#Cpio Child
close $brdr;
local $SIG{'PIPE'} = sub { Plumber("cpio") };
print "Staring first process.\n";
open(STDIN, $bkup_list) || die "doober! $!";
open(STDOUT, ">&", $bwtr) || die "foober! $bwtr";
print "This is a test.\n";
exec("cat");
die "Pipe Failed!";
}
close $bwtr;
while(!myselect($brdr)) {
print ".\n";
}
pipe $srdr, $swtr;
unless($bzippid = fork) {
#Bzip child
close $srdr;
local $SIG{'PIPE'} = sub { Plumber("bzip") };
print "Starting second process\n";
open(STDIN, "<&", $brdr) || die "Shriek?";
open(STDOUT, ">&", $swtr) || die "Bzip 2";
print "Some data here.\n";
exec("cat");
die "Pipe failed!";
}
close $brdr;
close $swtr;
while(!myselect($srdr)) {
print ".\n";
}
while($size = sysread($srdr, $_, 200)) {
syswrite(STDOUT, $_, $size);
}
#######################################################
sub myselect {
my $rdh;
foreach(@_) {
vec($rdh, fileno($_), 1) = 1;
}
my $nfound = select($rdh, undef, undef, .250);
print "Beep!\n";
return $nfound;
}
--=-=-=
Starling
--=-=-=--
------------------------------
Date: 9 Nov 2002 12:37:15 -0800
From: zoaraster@mailcity.com (kramer)
Subject: randomizing results from a mysql database
Message-Id: <9e811fcc.0211091237.6ea7738b@posting.google.com>
i have a people matching script which accesses a mysql database of
elements and returns matches one at a time based on some parameter
ranges (so the user gets a return match, clicks next, gets another,
etc...). what is the most efficient way to return those results
randomly and minimize or eliminate repeating matches.
------------------------------
Date: Sat, 09 Nov 2002 19:33:40 GMT
From: Kirk Is <kirkspam@alienbill.com>
Subject: Re: Safest way to convert $d.cc to $DCC ?
Message-Id: <oqdz9.295$Y2.12128@news.tufts.edu>
Alan J. Flavell <flavell@mail.cern.ch> wrote:
> On Nov 9, Kirk Is inscribed on the eternal scroll:
>> Tad McClellan <tadmc@augustmail.com> wrote:
>> Yeah, I know, but the incoming source has a decimal point.
> That doesn't make it into a floating point number. That seems to be a
touche
> common misapprehension, but a fixed-point number can be treated as an
> integer as long as you take care of the position of the point
> separately.
Yeah, by "floating point" I meant "some scalar that perl will probably
treat as a floating point if I naively multipled it by 100 which was my
very first thought but being only a half naive guy I'll come over to
Usenet and ask the smart folks on comp.lang.perl.misc"
> Which is in effect what is being recommended here:
>> > Use cents (integers) instead of dollars.
>> Yup.
> See?
I do.
>> It's data I'm getting from an Oracle db, somefield that's
>> like NUMBER(14,2) or some such. Oracle keeps that stuff safe,
>> right? Something closer to string handling (is packed decimal
>> the term?) than floating point.
> Why should it matter how the database actually _stores_ it, as long as
> it maintains precision? - all that you need to know is what your
> programming interface to the database API requires.
> (Back in IBM mainframe days, the term "packed decimal" referred to a
> decimal number having an odd number of digits, which was packed like
> dd dd dd ds , two digits per byte with "s" as the sign indicator.
> But you probably don't need to know that ;-)
Yeah, I was trying to remember the terms from my comp sci past.
Two's Complement, One's Complement, Packed Decimal...I thought there was
some term for storing a non integer as two seperate integers. Which might
be what Oracle is doing, or not.
I guess the only danger would be how well it "maintained precision". If
you put one number in, and its internal storage compelled the system to
not give you the same value when you got it out. that would be bad.
--
QUOTEBLOG: http://kisrael.com SKEPTIC MORTALITY: http://kisrael.com/mortal
"I'm a good influence on everyone I meet-- but they don't realize until
decades later. That's what I keep telling myself." --David Johnson
------------------------------
Date: Sat, 9 Nov 2002 15:29:52 -0500
From: "Bill Wheaton" <billwheaton@mindspring.com>
Subject: Re: significance of 42 for perl, any?!?
Message-Id: <aqjrgn$4nl$2@slb5.atl.mindspring.net>
"Michele Dondi" <bik.mido@tiscalinet.it> wrote in message
news:mp7tru48ukmha3498ljr0e04b71c7hrtsj@4ax.com...
> On Tue, 29 Oct 2002 13:32:42 GMT, helgi@decode.is (Helgi Briem) wrote:
>
> >>>> > Is there any particular significance of 42 for perl or is it just
my impression?
> >>>>
> >>>> Its the answer to the question about Life, the Universe, and
Everything. We
> >>>> don't know what the question is, but when we do, its answer will be
42.
> >>>
> >>> I thought the question was, 'What is 8x7?'
> >>
> >>AFAIK, 8x7 is "8888888". You probably meant 8*7.
> >
> >AFAIK, you are both wrong. 8*7 is not 42. 6*7 is.
>
> This thread is becoming definitely instructive at last!! :-)
> BTW: thanks for the answers.
>
>
> Michele
> --
> Liberta' va cercando, ch'e' si' cara,
> Come sa chi per lei vita rifiuta.
> [Dante Alighieri, Purg. I, 71-72]
>
> I am my own country - United States Confederate of Me!
> [Pennywise, "My own country"]
42 is the answer.
The question is:
"What do you get when you multiply six by nine?"
The answer according to the Hitch Hikers Guide, is the whole problem with
the world as we know it, because we've always assumed the question has to do
with the product of six, and seven. Something is missing, and it must be
found in a different dimention, or perhaps, our very existance is merely an
experiment by beings from that dimention with protuberances into ours that
show up to us as white mice.
Definately something to have Deep Thoughts about!
(yuk yuk, couldn't resist)
I quite often use 'lifetheuniverseandeverything42' or even
'ihaveapainrunningdownallthediodesinmyspine' as delimeter strings. And
while a flapper in the 1920's may have uttered '23 skidoo', 'isn't that just
tickeddyboo' has long been a part of my vocabulary. Those who get it, get
it. Those who don't, well, its just tickeddyboo by me.
Any programming language that can be explained using the Flintstones,
Jetsons, and 'solongandthanksforallthefish' is fine by me. Foo, bar, baz
and friends can go jump in a lake for all I care. Give me zephod
beeblebrox, marvin, fred, wilma, barney, betty, elroy, george, jane,
hiswife, and dino any day.
And don't forget where the name for the language translation 'babblefish'
comes from!
-bw
------------------------------
Date: Sat, 9 Nov 2002 15:47:56 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Simple, almost stupid question!
Message-Id: <slrnasr0kc.2lo.tadmc@magna.augustmail.com>
Rick Denoire <100.17706@germanynet.de> wrote:
> perl -p -i -e 's/$old/$new/g' target_file
> I do have more than 200 such commands to execute on a number of files
> as target. Let's assume that I have a file sub_list
> Since perl should be able to read the commands from a file, I am
> looking for the correct option to do this:
perldoc -f require
> so the file would look like this:
%subst = qw(
this that
white black
high low
);
(word-wrapped for posting)
perl -p -i -e 'BEGIN{ require "sub_list"; $a = join "|", keys %subst}
s/($a)/$subst{$1}/g' files...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 09 Nov 2002 22:22:01 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Simple, almost stupid question!
Message-Id: <dUfz9.17425$XG3.8930@news4.srv.hcvlny.cv.net>
"Rick Denoire" <100.17706@germanynet.de> wrote in message
news:g6jqsuc60otkfqoajk3gs2g2v81jksv2qs@4ax.com...
> Hello
>
> Take a look to this line:
> perl -p -i -e 's/$old/$new/g' target_file
>
> meaning to replace $old by $new in the target file.
> But if using a large number of substitute commands, the line would get
> too long: "-e command1 -e command2 -e command3 ...."
>
> I do have more than 200 such commands to execute on a number of files
> as target. Let's assume that I have a file sub_list with two columns
> containing $old in the first and $new in the second column:
>
> this that
> white black
> high low
> etc
>
> Since perl should be able to read the commands from a file, I am
> looking for the correct option to do this:
>
> echo "target1 target2 ...." | xargs perl -p -i <option> sub_list
>
> So I would apply all commands contained in sub_list to all target
> files. Would that be possible? I just don't know what the <option>
> should be (I warned, this is a stupid question). Of course, I could
> create sub_list containing the commands needed for perl, not only the
> substitution strings, so the file would look like this:
>
> s/this/that/g
> s/white/black/g
> s/high/low/g
> etc.
>
> (not sure if I should enclose every line, or the whole block of lines
> in apostrophes, or perhaps without any at all). Btw, if $old is not
> found in a file, that should not break the perl call.
>
> Sorry for this simple question, I am a casual perl user and even after
> I went through a whole book I could not find the answert to this
> question.
>
> (using Solaris 2.7 and perl 5.0)
>
> ANY hint would be highly appreciated!
"The Perl Cookbook" gives three solutions, with their advantages, in recipe
1.17. The examples are given as filters. You may want to use the -i flag.
(refer perldoc perlrun)
Have fun,
Bill
------------------------------
Date: Sat, 09 Nov 2002 21:55:28 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: wish fast method of counting of characters
Message-Id: <3DCD843E.58423D9D@acm.org>
John Sellers wrote:
>
> I am going to be doing a lot of counting of characters from a large list
> of strings.
>
> What is the fastest way to do this?
The fastest way is to use substr() to count the characters.
$count{ord(substr($nextString,$_,1))}++ for 0..length($nextString)-1;
> I know that unpack is pretty fast.
> But is this the way to do it?
If you _HAVE_ to convert the string to an array of characters, then
unpack will be faster (depending on length of string. YMMV.)
> Here is some self contained working sample code, do I have as good an
> answer as I am going to get with pure Perl?
>
> #Typical string
> $nextString = "bbxslkfjlskjflksdjflksdjfljsdfljsdflkjsdlfkj\n";
>
> # START TIME CRITICAL CODE
> @asciiList = unpack( "C*", $nextString );
> foreach $anAsciiNumber (@asciiList) {
> # does the hash context conversion of $anAsciiNumber to string slow
> # things down?
> $count{$anAsciiNumber}++
> }
> # END TIME CRITICAL CODE
>
> $ordNewline = ord("\n");
> delete $count{$ordNewline};
Why don't you just chomp() the string _before_ you count characters?
> @charStrings =sort map( chr, keys %count);
>
> foreach $charString ( @charStrings ) {
> $asciiValue = ord( $charString);
>
> print "$charString: $count{$asciiValue}\n";
> }
If you find yourself asking the question "Which is faster?" then you
want to use the Benchmark module.
#!/usr/bin/perl
use warnings;
use strict;
use Benchmark qw/cmpthese/;
my $gstring = join( '', ( 'a' .. 'z' ) ) x 1000;
cmpthese( -120, {
unpack1 => sub {
my $string = $gstring;
my %count;
# START TIME CRITICAL CODE
my @asciiList = unpack( 'C*', $string );
for my $anAsciiNumber ( @asciiList ) {
# does the hash context conversion of $anAsciiNumber to
string slow
# things down?
$count{$anAsciiNumber}++
}
# END TIME CRITICAL CODE
return \%count;
},
unpack2 => sub {
my $string = $gstring;
my %count;
$count{$_}++ for unpack 'C*', $string;
return \%count;
},
split => sub {
my $string = $gstring;
my %count;
$count{ord}++ for split //, $string;
return \%count;
},
regex => sub {
my $string = $gstring;
my %count;
$count{ord}++ for $string =~ /./g;
return \%count;
},
substr => sub {
my $string = $gstring;
my %count;
$count{ord substr $string, $_, 1}++ for 0 .. length($string) -
1;
return \%count;
},
} );
__END__
John
--
use Perl;
program
fulfillment
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.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 V10 Issue 4091
***************************************