[27818] in Perl-Users-Digest
Perl-Users Digest, Issue: 9182 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 20 18:05:53 2006
Date: Thu, 20 Apr 2006 15:05:09 -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 Thu, 20 Apr 2006 Volume: 10 Number: 9182
Today's topics:
damned whitespace (was: Re: show hidden value in variab <rvtol+news@isolution.nl>
Re: FAQ 4.41 How can I remove duplicate elements from a <Juha.Laiho@iki.fi>
Re: FAQ 4.47 How do I handle circular lists? <uri@stemsystems.com>
Re: How to find uploaded data size from content-length <john@castleamber.com>
Re: How to find uploaded data size from content-length <no@thanks.com>
Re: How to find uploaded data size from content-length <no@thanks.com>
Re: How to find uploaded data size from content-length <no@thanks.com>
Re: How to find uploaded data size from content-length <no@thanks.com>
Re: How to find uploaded data size from content-length <no@thanks.com>
Re: How to find uploaded data size from content-length <john@castleamber.com>
Re: problem reading quoted text [was: How to find uploa <××DBraughler××@××bwcc·com>
Re: Term::ReadKey on Win? 5.005 vs 5.8.8? <nospam-abuse@ilyaz.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 20 Apr 2006 21:52:00 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: damned whitespace (was: Re: show hidden value in variable.. with mysql)
Message-Id: <e28vs9.1ik.1@news.isolution.nl>
Anno Siegel schreef:
> Dr.Ruud:
>> joe.henderson1@:
>>> $item =~ s/^\s+//; #remove Leading whitespace
>>> $item =~ s/\s+$//; #remove trailing whitespace
>>> $item =~ s/\r/ /g; #remove those Damn ^M
>>> $item =~ s/\f/ /g; #remove those Damn ^M
>>> $item =~ s/\t/ /g; #remove those Damn ^M
>>> $item =~ s/\n/ /g; #remove those Damn ^M
>>> $item =~ s/\s+/ /g; #replace multiple spaces with one
>>> chomp($item); #remove newline character
>>
>> After some weeding, this remains:
>>
>> s/^\s+//, s/\s+$//, s/\s+/ /g for $item; (1)
>
> ...or even
>
> s/\s+/ /g, s/^\s//, s/\s$// for $item; (2a)
Heheh, it was already one step further:
s/\s+/ /g, s/^ //, s/ $// for $item; (2b)
Next steps:
(3) A variant with the "/x" modifier.
(4) A multiline-variant that lets the linebreaks stay.
My first tries, not yet tested or optimized or Unicode-ready:
s/\s+/\x{20}/gx, s/^\x{20}/x, s/\x{20}$//x for $item; (3)
(EBCDIC & friends just left the building)
s/[\x{20}\f\r\t]+/\x{20}/gmsx, s/^\x{20)/gmsx, s/\x{20}$//gmsx for
$item; (4)
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Thu, 20 Apr 2006 18:39:23 +0000 (UTC)
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: FAQ 4.41 How can I remove duplicate elements from a list or array?
Message-Id: <e28kgr$58p$1@ichaos2.ichaos-int>
robic0 said:
(referring to code
my @unique = grep { ! $seen{ $_ }++ } @array;
in the FAQ 4.41 entry)
>Ok, just need some clarification here.
>I can't quite make out this syntax.
>I am asuming that $seen{ $_ }++ means exists so the '!'
>returns true/false.
Yep, quite a few things happen "at once" here.
- the "seen" hash is being searched for the key $_
- if the key wasn't found, a new key-value pair will be created,
the value defaulting to "undef"
- the value for the key (either the existing value, or the newly
created value) is returned from the expression
- the stored value (but not the returned!) is incremented by one,
thus, if the value was newly created, it will now become "1"
- the ! operator will make a logic negation, thus if the hash
operation returned "undef" (for a key that didn't previously exist
in the hash), the grep will see the result as logic "true"; all
later accesses with the same key will return false (as ! applied
to any nonzero number will return "false")
... so, "unique" array will be assigned only unique values from
the "array" array -- and in the exact order in which they appear in
the "array".
>The fact is that a hash key lookup is both searched for and if not exists,
>then added to the array. The syntax is irrelavent!
The syntax is relevant to that extent, that it returns different result
for the first access with a given key then for any subsequent access
with the same key.
>I will have to stand by my analogy that binary search is used in both
>the searching for the key and the existence simutaneously.
It's a hash lookup, which has potential to be faster than binary search
for the common case.
>However, this begs the question of why there is no direct memmove
>primitive in Perl?
Why should there be? Perl is on a different abstraction level (much of
the time, at least). Memory addresses are not a typical abstraction
in perl. The closest to memmove is that array (and hash) slices are
assignable. But as you saw, the memmove is irrelevant for the hash
case -- and behind the scenes, building the hash could very well use
the C memmove. But on the Perl level you just don't need to care.
Trust that if you use hash in the correct place for your code, it
will perform fast enough.
>The user should be given the option. Memmove is the core to
>growing/shrinking arrays at mid-point,
>not just at the beginning and end with the shift/unshift and push/pop.
As said, array and hash slices are assignable.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
------------------------------
Date: Thu, 20 Apr 2006 17:43:53 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: FAQ 4.47 How do I handle circular lists?
Message-Id: <x7ejzr3oti.fsf@mail.sysarch.com>
>>>>> "r" == robic0 <robic0> writes:
r> On Thu, 20 Apr 2006 00:03:03 -0700, PerlFAQ Server <brian@stonehenge.com> wrote:
>> This is an excerpt from the latest version perlfaq4.pod, which
>> comes with the standard Perl distribution. These postings aim to
>> reduce the number of repeated questions as well as allow the community
>> to review and update the answers. The latest version of the complete
>> perlfaq is at http://faq.perl.org .
>>
>> --------------------------------------------------------------------
>>
>> 4.47: How do I handle circular lists?
>>
>> Circular lists could be handled in the traditional fashion with linked
>> lists, or you could just do something like this with an array:
>>
>> unshift(@array, pop(@array)); # the last shall be first
>> push(@array, shift(@array)); # and vice versa
>>
>>
>>
>> --------------------------------------------------------------------
>>
>> The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
>> are not necessarily experts in every domain where Perl might show up,
>> so please include as much information as possible and relevant in any
>> corrections. The perlfaq-workers also don't have access to every
>> operating system or platform, so please include relevant details for
>> corrections to examples that do not work on particular platforms.
>> Working code is greatly appreciated.
>>
>> If you'd like to help maintain the perlfaq, see the details in
>> perlfaq.pod.
>> *** Posted via a free Usenet account from http://www.teranews.com ***
r> Whats a "Circular List"? Is that a ring buffer? If it is, is your
r> context correct, and what would you imagine its uses for?
your constant claim to know all of cs is wearing thin (not that anyone
here really thought you knew much). as with hashes, this is a
fundamental type of data structure and you need to get a good book on
this and read it. and you will learn a ton more and stop having to ask
silly questions about basic programming and structures.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 20 Apr 2006 18:12:50 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: How to find uploaded data size from content-length
Message-Id: <Xns97AB866B8AA64castleamber@130.133.1.4>
Sherm Pendley <sherm@dot-app.org> wrote:
> Asterbing <no@thanks.com> writes:
>
>> I've seen and rewritten my own. A matter of courtesy to not 'copy' :
>> in my mind, two ways only : I use a module or I just take a look of
>> their algorithm (idea), but never copy (steal)
>
> I suppose you rewrote perl too, using a C compiler you rewrote? What
> about the web server, and the operating system? You wouldn't want to
> "steal" those either, now would you?
>
> Idiot.
Not really: he wrote: I either use the full product (in your example perl,
c compiler, web server. In his example CGI.pm) *or* I write my own, and
when possible I look at their source, but I don't copy it 1:1. Doesn't
sound like an idiot to me. At least he takes the time to study someone
else's code.
> *plonk*
Uncalled for IMO. Also how many people are interested in the status of
your kf?
--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/
------------------------------
Date: Thu, 20 Apr 2006 22:58:51 +0200
From: Asterbing <no@thanks.com>
Subject: Re: How to find uploaded data size from content-length
Message-Id: <MPG.1eb21472b12df22998980f@news.tiscali.fr>
In article <m2bquww5xn.fsf@Sherm-Pendleys-Computer.local>, sherm@dot-
app.org says...
> > I don't use CGI.pm
>
> Why on earth not? Do you enjoy pain?
>
Not pain, enthousiasm ;)
------------------------------
Date: Thu, 20 Apr 2006 23:05:53 +0200
From: Asterbing <no@thanks.com>
Subject: Re: How to find uploaded data size from content-length
Message-Id: <MPG.1eb2162040a4c5e2989810@news.tiscali.fr>
In article <124etlfl74k487@corp.supernews.com>, ××DBraughler××@××bwcc·
com says...
> Then your Gravity news agent is messed up or you miscounted the nesting wakas.
> The attributions and text are correctly nested in what I posted.
>
My Gravity show me this about your post I told about :
--- BEGIN COPIE ---
Asterbing wrote:
> [quoted text muted]
>>
>> That should probaby be changed. It does not immediately exit with
>> an error message. It first reads (and discards) the entire contents
>> of the POST, which apparently the OP doesn't want to happen
--- END COPIE ------
------------------------------
Date: Thu, 20 Apr 2006 23:08:14 +0200
From: Asterbing <no@thanks.com>
Subject: Re: How to find uploaded data size from content-length
Message-Id: <MPG.1eb216a46f4215d4989811@news.tiscali.fr>
In article <dkjkh3xvqa.ln2@goaway.wombat.san-francisco.ca.us>, kkeller-
usenet@wombat.san-francisco.ca.us says...
> Copying isn't stealing if you're allowed to do it. Just don't
> redistribute your program without also distributing the source.
>
Don't know if the author(s) of CGI.pm allow this. However, about Perl,
source is always visible, by design.
------------------------------
Date: Thu, 20 Apr 2006 23:08:44 +0200
From: Asterbing <no@thanks.com>
Subject: Re: How to find uploaded data size from content-length
Message-Id: <MPG.1eb216ca5c8ad4b9989812@news.tiscali.fr>
In article <m2y7y0uqs2.fsf@Sherm-Pendleys-Computer.local>, sherm@dot-
app.org says...
> I suppose you rewrote perl too, using a C compiler you rewrote? What about
> the web server, and the operating system? You wouldn't want to "steal" those
> either, now would you?
>
Irrelevant : C is not an interpreted language !
------------------------------
Date: Thu, 20 Apr 2006 23:11:14 +0200
From: Asterbing <no@thanks.com>
Subject: Re: How to find uploaded data size from content-length
Message-Id: <MPG.1eb217586ef596df989813@news.tiscali.fr>
In article <Xns97AB866B8AA64castleamber@130.133.1.4>,
john@castleamber.com says...
> Not really: he wrote: I either use the full product (in your example perl,
> c compiler, web server. In his example CGI.pm) *or* I write my own, and
> when possible I look at their source, but I don't copy it 1:1. Doesn't
> sound like an idiot to me. At least he takes the time to study someone
> else's code.
>
Thanks John : we're at least two ;-) ... No, sure we're a lot :)
------------------------------
Date: 20 Apr 2006 21:11:59 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: How to find uploaded data size from content-length
Message-Id: <Xns97ABA4CA8C9FFcastleamber@130.133.1.4>
Asterbing <no@thanks.com> wrote:
> In article <m2y7y0uqs2.fsf@Sherm-Pendleys-Computer.local>, sherm@dot-
> app.org says...
>> I suppose you rewrote perl too, using a C compiler you rewrote? What
>> about the web server, and the operating system? You wouldn't want to
>> "steal" those either, now would you?
>>
>
> Irrelevant : C is not an interpreted language !
http://www.google.com/search?q=C%20interpreter
--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/
------------------------------
Date: Thu, 20 Apr 2006 17:35:08 -0400
From: Denver <××DBraughler××@××bwcc·com>
Subject: Re: problem reading quoted text [was: How to find uploaded data size from content-length]
Message-Id: <124fvkeocvcfp5b@corp.supernews.com>
Asterbing wrote:
> In article <124etlfl74k487@corp.supernews.com>, ××DBraughler××@××bwcc·
> com says...
>> Then your Gravity news agent is messed up or you miscounted the nesting wakas.
>> The attributions and text are correctly nested in what I posted.
>
> My Gravity show me this about your post I told about :
>
> --- BEGIN COPIE ---
> Asterbing wrote:
>> [quoted text muted]
>>>
>>> That should probaby be changed. It does not immediately exit with
>>> an error message. It first reads (and discards) the entire contents
>>> of the POST, which apparently the OP doesn't want to happen
> --- END COPIE ------
That certainly is not what I posted.
Nonetheless, it is quite clear from that that anything that Asterbing wrote is preceded by ">>" not by ">>>".
------------------------------
Date: Thu, 20 Apr 2006 20:42:46 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Term::ReadKey on Win? 5.005 vs 5.8.8?
Message-Id: <e28ro6$1o6u$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Sisyphus
<sisyphus1@nomail.afraid.org>], who wrote in article <44472924$0$7529$afc38c87@news.optusnet.com.au>:
> Fwiw, the bug can be demonstrated with a simpler command:
>
> perl -MTerm::ReadKey -e "ReadMode 4;while(1){$k = getc; print ord($k),
> \"\n\"}"
I presume you meant to print
perl -MTerm::ReadKey -wle "ReadMode 4; print ord getc while 1"
But this is not what I'm interested in; you are reading from STDIN; it
may be CONIN$, but maybe it is not. Could you check the file name to
which STDIN is connected? On OS/2 POSIX::ttyname() would work; do not
know about Win*...
> Switching to 'ReadMode 0' in the above command means
Sorry, I can't understand what is the purpose of the rest of your
message... Do you change 4 to 0 in the above code? Then what you do
is just
perl -wle "print ord getc while 1"
and I do not see anything deserving attention in how you describe its
effects. :-(
Thanks anyway,
Ilya
------------------------------
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 V10 Issue 9182
***************************************