[29050] in Perl-Users-Digest
Perl-Users Digest, Issue: 294 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 2 18:09:39 2007
Date: Mon, 2 Apr 2007 15:09:05 -0700 (PDT)
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, 2 Apr 2007 Volume: 11 Number: 294
Today's topics:
Re: Apache, perl and WinXP cmd.exe - problem with perce <bik.mido@tiscalinet.it>
Re: comp.lang.perl.cgi? <noreply@gunnar.cc>
Re: comp.lang.perl.cgi? <noreply@gunnar.cc>
Re: comp.lang.perl.cgi? <spamtrap@dot-app.org>
Re: comp.lang.perl.cgi? <thepoet_nospam@arcor.de>
Re: equivalence of variables question <please@nospam.net>
Re: order of evaluation <please@nospam.net>
Re: Problem in the Perl script <please@nospam.net>
Re: Problem in the Perl script <hjp-usenet2@hjp.at>
Re: Problem in the Perl script <bik.mido@tiscalinet.it>
Re: TCP Server+perl <himagauri@gmail.com>
Re: TCP Server+perl <spamtrap@dot-app.org>
Re: Trailing whitespace question <bik.mido@tiscalinet.it>
Re: Trailing whitespace question <rvtol+news@isolution.nl>
Re: Trailing whitespace question <bik.mido@tiscalinet.it>
Re: what's wrong with this OR statement syntax <please@nospam.net>
Re: what's wrong with this OR statement syntax <glennj@ncf.ca>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 02 Apr 2007 20:13:08 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Apache, perl and WinXP cmd.exe - problem with percent sign in arg list
Message-Id: <lfh213drr488dg1n8o9dkk8euhkcnt9ol8@4ax.com>
On Mon, 02 Apr 2007 16:22:13 GMT, "Jürgen Exner"
<jurgenex@hotmail.com> wrote:
>> On 2 Kwi, 17:06, Purl Gurl <purlg...@purlgurl.net> wrote:
>
>Oh, it is back. It is back. Amazing! Haven't seen it in a long time.
You didn't pay much attention:
http://use.perl.org/~blazar/journal/32854
;-)
>>> variables as global variables. This is not a good practice.
>
>Absolutely agree. Use of global variables usually indicate poor coding
>style.
In all earnestness and with due respect to you... idiot! Can't you
just pick a random entry from
http://images.google.com/images?q=%22don%27t+feed+the+troll%22
and shut up? I can imagine her in this moment, scratching her crotch
by happiness of having an anal retentive like she thinks you are, go
mad on her intervention once again...
>>> Should you be using the broken "strict" module, use "our"
>>> for declaring global variables, which also serves no purpose
>>> other than to place a band-aid on the broken strict module.
>
>Which of course is utter nonsense. But what would you expect from it.
But then, one does infer that you *do* have her killfiled... I
wouldn't answer unless I see signs of the poor newbie eating her pile
o' crap. But even then, one gets what he/she deserves...
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Mon, 02 Apr 2007 20:37:27 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: comp.lang.perl.cgi?
Message-Id: <57d0vbF2aqhalU1@mid.individual.net>
Charlton Wilbur wrote:
>>>>>>"GH" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
>
> GH> The group comp.infosystems.www.authoring.cgi has been down for
> GH> several months. As far as I can understand, it means that
> GH> there is no longer an appropriate Usenet group for those who
> GH> use Perl for web applications to discuss CGI and HTTP matters.
>
> On the contrary; it means that there is an appropriate Usenet group,
> which nobody happens to be using.
No, the (moderated) group mentioned is out of order.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 02 Apr 2007 21:47:09 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: comp.lang.perl.cgi?
Message-Id: <57d520F2d959iU1@mid.individual.net>
Charlton Wilbur wrote:
>>>>>>"GH" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
>
> GH> Maybe it's time to establish the group comp.lang.perl.cgi?
>
> The procedure for creating a new newsgroup is well-established and
> well-known. Have fun!
Well, I didn't ask how to do it. I was simply hoping for a few informal
responses on whether it would be a good idea.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 02 Apr 2007 16:02:56 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: comp.lang.perl.cgi?
Message-Id: <m23b3ir1cf.fsf@local.wv-www.com>
Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
> The group comp.infosystems.www.authoring.cgi has been down for several
> months. As far as I can understand, it means that there is no longer
> an appropriate Usenet group for those who use Perl for web
> applications to discuss CGI and HTTP matters.
comp.infosystems.www.authoring.cgi
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Mon, 02 Apr 2007 23:40:11 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: comp.lang.perl.cgi?
Message-Id: <4611782b$0$20298$9b4e6d93@newsspool3.arcor-online.net>
Gunnar Hjalmarsson wrote:
> The group comp.infosystems.www.authoring.cgi has been down for several
> months. As far as I can understand, it means that there is no longer an
> appropriate Usenet group for those who use Perl for web applications to
> discuss CGI and HTTP matters.
>
> Maybe it's time to establish the group comp.lang.perl.cgi?
I'm not sure if that is really needed. I've counted 670 postings
with a subject of cgi in clp.misc for the last ten months, where
not every one of the threads was even really cgi related.
clp.misc is still readable, so I don't see an urgent need to split
some parts off into more specific groups. From experience in the
German hierarchy, where de.comp.lang.perl.cgi exists in parallel
with de.comp.lang.perl.misc, cgi related traffic is decreasing
anyway and specific mod_perl questions don't hit the usenet very
often (mostly just scoping issues that aren't exlusive to mod_perl).
That's just my personal opinion, of course, but I believe that
as long as the number of postings for a specialised group is
below some treshold the annoyance about misplaced questions tends
to outweigh the comfort of having separate "views".
Maybe something like comp.lang.perl.web+cgi+mod_perl would be
appropriate to bundle anything web related, but I can't imagine
a short and easy to understand name that lets newbies find their
way there.
-Chris
------------------------------
Date: Mon, 02 Apr 2007 01:16:11 -0700
From: Xiong Changnian <please@nospam.net>
Subject: Re: equivalence of variables question
Message-Id: <please-F2A7E5.01161102042007@free.teranews.com>
In article <m2wt1ro8hj.fsf@local.wv-www.com>,
Sherm Pendley <spamtrap@dot-app.org> wrote:
> The lines in @image_names each have a newline at the end, but $SKU does not.
> Adding the quotes around the output will make that more apparent.
My usual print-for-debug line is:
print (">$foo< \n");
This makes this kind of thing stand out. I've been bitten this way
myself. chomp-ing may be helpful.
--
Xiong Changnian
xiong102ATxuefangDOTcom
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Mon, 02 Apr 2007 04:41:51 -0700
From: Xiong Changnian <please@nospam.net>
Subject: Re: order of evaluation
Message-Id: <please-E68613.04415102042007@free.teranews.com>
In article <1174919585.312853.44560@p77g2000hsh.googlegroups.com>,
"Flo" <sensorflo@gmail.com> wrote:
> I'd like to know the name of the rule which states why the first
> and not the second star * greedely matches all.
Um, I'm not sure it's directly stated. Others have posted sources that
the regexp is evaluated left-to-right. By the time the second * comes
up, there isn't anything "remaining" of the target.
--
Xiong Changnian
xiong102ATxuefangDOTcom
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Mon, 02 Apr 2007 04:07:38 -0700
From: Xiong Changnian <please@nospam.net>
Subject: Re: Problem in the Perl script
Message-Id: <please-78A71C.04073802042007@free.teranews.com>
In general, you don't want to test floating-point numbers for equality.
It will almost always bring you to grief. Some would put it even more
strongly.
Perl has no fixed-point numeric format. There are only integers and
floats. If a variable has *ever* stored a non-integer value, it will
want to use floating-point format.
I like to think of integers as digital values, floats as analog values.
It's possible to say truthfully, for example:
"I have some marbles in this cup. I have some apples in this basket. The
number of marbles is exactly equal to the number of apples."
However, this statement is fraught with peril:
"I have a red stick and a blue car. The length of the stick is exactly
equal to the length of the car."
There is no way to verify this, because you cannot measure either stick
or car with infinite precision.
There are ideal situations in which it is true that two analog
quantities are equal. For instance, in the standard construction of an
equilateral triangle with compass and straightedge, the length of each
side is an analog quantity that we'd probably represent with a float. By
definition, all these lengths are exactly equal. If we were to calculate
these lengths using floating-point variables, they might not test as
equal, though.
But such situations only occur in ideal space. Real-world analog
quantities, represented by real numbers, can never be determined to be
exactly equal. All we can ever say is that they are equal to the limits
of our measurement method.
my $truth;
my $num = 0.000003;
my $lim = 0.0003;
$num = $num * 100;
$truth = ($num == $lim) ? 'true' : 'false';
print ("$num, $lim, $truth \n");
... outputs:
0.0003, 0.0003, false (at least on my machine)
Testing for float equality is especially risky because floats are *not*
infinite-precision real numbers. You might get "lucky" with a test case
or two and think your code works. Developing the code above, I
experimented with some "simpler" examples which tested 'true'.
Testing for float equality is a sign that you need to rethink what you
are doing. Why do you want to do this? Get out of the code for a moment
and look at the real-world situation. What analog variables could you
want to be exactly equal?
Here, I want to know when I've cooked my breakfast long enough:
sub cook {
# cook eggs for six seconds
return 0.1;
};
my $time = 0;
my $done = 3; # minutes
do {
$time += cook();
} until $time == $done;
print ("$time, $done \n");
This loop will never exit until I run screaming into a kitchen full of
smoke. However, if I change the test to:
until $time >= $done;
... the program will exit happily with output:
3, 3
Eggs are never *exactly* done but there is a time when they are done
enough. The reason that perl prints 3 for $time is that an ugly detail
is being hidden from you -- it is *not* exactly 3.
In other cases, you might be better to use an explicit, integer
iterator:
for (my $i = 0, $i == $max, $i++) {
$time += cook();
};
Of course, you have to choose $max wisely.
Another approach is to test the eggs themselves for doneness:
sub cook {
# cook eggs for six seconds
return 0.1;
};
sub done {
# return 1 if eggs look done, 0 otherwise
};
do {
cook();
} until done();
print ("Done! \n");
You have to decide what a done egg looks like. This works well for fried
eggs, not well for boiled eggs.
A different need might involve biometric data. Your secret agent steps
on a scale before being granted access to the men's room:
%::metrics = (
SMITH => 143.24,
JONES => 175.02,
);
sub pass_agent {
print (">agent passed< \n");
};
sub incinerate_agent {
print (">agent incinerated< \n");
};
sub weigh {
# return weight from scale device
143.2400001;
};
sub verify_agent {
my $agent = shift;
my $weight = weigh();
if ($weight == $::metrics{$agent}) {
pass_agent();
}
else {
incinerate_agent();
};
};
verify_agent ('SMITH');
Agent Smith will always be incinerated because there is no way for him
to weigh *exactly* as much as he did back when you created the
%::metrics "database". (Yes, that should be a tied hash. Okay?) Every
time Smith breathes, he gains or loses some trivial amount of weight.
What if we declare some very small value by which Smith's weight is
allowed to vary?
$::epsilon = 0.01;
We change our test to:
if ( abs ( $weight - $::metrics{$agent} ) < $::epsilon ) {...
Smith will still want to watch that extra donut but at least he has a
chance of making it to the men's room.
In still another case, you're not using an analog value at all but it
appears to be a fraction or decimal. For example, you are turning a
rotary switch through a full circle. There are eight detents in the
switch, so you say:
my $click = 1/8; # one-eighth of a turn
my $turn = 1;
Later, you accumulate clicks until you reckon you've made a full turn.
This may fail but a slightly different approach succeeds:
my $click = 1;
my $turn = 8; # eight clicks
* * *
I suggest that if you think it over, you'll see that you never *want* to
test floats for equality. It's not a matter of language; it's a matter
of your intent.
To tell the truth, I rarely test an *integer* for == if I've done any
sort of arithmetic operations on it other than ++. If I'm exiting a
loop, I test (as above) for >=. This is doubtless excessively paranoid
but I'd rather exit with the wrong number of iterations than not exit at
all.
--
Xiong Changnian
xiong102ATxuefangDOTcom
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Mon, 2 Apr 2007 21:44:24 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Problem in the Perl script
Message-Id: <slrnf12n8o.71i.hjp-usenet2@yoyo.hjp.at>
On 2007-04-02 11:07, Xiong Changnian <please@nospam.net> wrote:
> In general, you don't want to test floating-point numbers for equality.
> It will almost always bring you to grief. Some would put it even more
> strongly.
>
> Perl has no fixed-point numeric format. There are only integers and
> floats. If a variable has *ever* stored a non-integer value, it will
> want to use floating-point format.
>
> I like to think of integers as digital values, floats as analog values.
While that will prevent you from making one set errors, it will lead you
to another set.
Floating point values are not analog. They are discrete, just like
integers. There is a finite set of different floating point numbers (for
a given implementation), each of them has an exact value, and for each
of them (except the smallest and the largest) there is a smaller and a
larger neighbour, and there are no other FP numbers between a number and
its neighbours (just like there are no other integers between say 54 and
55).
> In still another case, you're not using an analog value at all but it
> appears to be a fraction or decimal. For example, you are turning a
> rotary switch through a full circle. There are eight detents in the
> switch, so you say:
>
> my $click = 1/8; # one-eighth of a turn
> my $turn = 1;
>
> Later, you accumulate clicks until you reckon you've made a full turn.
> This may fail but a slightly different approach succeeds:
Bad example. Given a binary floating point representation, this cannot
fail, because 1/8 is representable exactly.
hp
--
_ | Peter J. Holzer | Blaming Perl for the inability of programmers
|_|_) | Sysadmin WSR | to write clearly is like blaming English for
| | | hjp@hjp.at | the circumlocutions of bureaucrats.
__/ | http://www.hjp.at/ | -- Charlton Wilbur in clpm
------------------------------
Date: Mon, 02 Apr 2007 22:32:50 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Problem in the Perl script
Message-Id: <k2q213lpba7kqh97nuevjrb6ijjpdtogba@4ax.com>
On Mon, 02 Apr 2007 04:07:38 -0700, Xiong Changnian
<please@nospam.net> wrote:
>I like to think of integers as digital values, floats as analog values.
Nope, on a computer all values are discrete, period.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 2 Apr 2007 14:11:50 -0700
From: "Gauri" <himagauri@gmail.com>
Subject: Re: TCP Server+perl
Message-Id: <1175548310.308336.254540@p77g2000hsh.googlegroups.com>
Should I add a shutdown(SOCKET, 2) function to make sure the parent
is closed?
Any suggestions?
------------------------------
Date: Mon, 02 Apr 2007 17:41:20 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: TCP Server+perl
Message-Id: <m2y7lapi7z.fsf@local.wv-www.com>
"Gauri" <himagauri@gmail.com> writes:
> Should I add a shutdown(SOCKET, 2) function to make sure the parent
> is closed?
Add it to what?
> Any suggestions?
Here's one - quote enough of the message you're replying to for your own
message to make sense. Have you read the posting guidelines that appear
here frequently?
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Mon, 02 Apr 2007 21:17:32 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Trailing whitespace question
Message-Id: <3al213t0rqcmi1p8kmf0da0kc86j5vkobo@4ax.com>
On Mon, 02 Apr 2007 11:27:11 -0400, nun <junk@yahoo.com> wrote:
>I'm reading data from a text file into an array like this:
>
> push @AoA, [(
Why @AoA? It's just a plain array of strings...
> substr($_, 0, 4),
> substr($_, 4, 20),
> substr($_, 24, 30),
> substr($_, 54, 8),
> substr($_, 70, 8),
> substr($_, 103, 20),
> substr($_, 123, 1),
>)];
>
>
>I'd like to trim any trailing spaces from the substr($_, 24, 30) entry.
You want to know about =~.
>I see from Google that:
>
> s/ *$//;
If you want to be picky, s/ *\z// would be more precise. But what you
wrote may be what you want. If there are no newlines involved, they
will be the same.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Mon, 2 Apr 2007 21:26:04 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Trailing whitespace question
Message-Id: <eursov.b4.1@news.isolution.nl>
nun schreef:
> s/ *$//;
That should be
s/ +$//;
or even
s/\s+$//;
> substr($_, 0, 4),
> substr($_, 4, 20),
> substr($_, 24, 30),
> substr($_, 54, 8),
> substr($_, 70, 8),
> substr($_, 103, 20),
> substr($_, 123, 1),
Or
m/^(.{4})(.{20})(.{30})(.{8)).{8}(.{8)).{25}(.{20})(.)/s
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Mon, 02 Apr 2007 22:50:22 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Trailing whitespace question
Message-Id: <r1r213d6in2ombrs8ih8kvjv696mc8v5ea@4ax.com>
On Mon, 2 Apr 2007 21:26:04 +0200, "Dr.Ruud" <rvtol+news@isolution.nl>
wrote:
>> substr($_, 0, 4),
>> substr($_, 4, 20),
>> substr($_, 24, 30),
>> substr($_, 54, 8),
>> substr($_, 70, 8),
>> substr($_, 103, 20),
>> substr($_, 123, 1),
>
>Or
>
> m/^(.{4})(.{20})(.{30})(.{8)).{8}(.{8)).{25}(.{20})(.)/s
^ ^
^ ^
Or
unpack 'A4A20A30A8@70A8@103A20A1' => $_;
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Mon, 02 Apr 2007 01:28:28 -0700
From: Xiong Changnian <please@nospam.net>
Subject: Re: what's wrong with this OR statement syntax
Message-Id: <please-F31A61.01282802042007@free.teranews.com>
In article <GYOdnSv5IfaABGTYnZ2dnUVZ_h6vnZ2d@comcast.com>,
"Dan Mercer" <damercer@comcast.net> wrote:
> What you want is:
>
> if ($color =~ /^(red|blue|green)$/)
This one gets my vote.
--
Xiong Changnian
xiong102ATxuefangDOTcom
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: 2 Apr 2007 21:09:17 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: what's wrong with this OR statement syntax
Message-Id: <slrnf12s7v.319.glennj@smeagol.ncf.ca>
At 2007-03-15 03:14PM, "Mirco Wahab" wrote:
> levinepw@yahoo.com wrote:
> > I wanted a shorthand to
> > my $color='red';
> > if($color eq 'blue' || $color eq 'red' || $color eq 'green'))
> > {
> > print "cool\n";
> > }
> > Can someone tell me why my attempt doesn't work & if there is a
> > simpler way to write the statement.
>
> There have been some examples,
> so I'll add another one:
>
> ...
>
> sub IS { grep /\b$_[0]\b/, @{$_[1]} }
> sub IN { [@_] }
>
>
> my $color='red';
>
> if( IS $color, IN qw'blue red green' ) {
> print "cool\n";
> }
Far too late to help anyone, but here's another offering:
use List::Util 'first';
sub is_in_list {
my ($value, @list) = @_;
return defined(first {$_ eq $value} @list);
}
if (is_in_list $color, qw(blue white red)) {
# ...
}
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 294
**************************************