[19815] in Perl-Users-Digest
Perl-Users Digest, Issue: 2010 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 25 14:10:40 2001
Date: Thu, 25 Oct 2001 11:10:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1004033413-v10-i2010@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 25 Oct 2001 Volume: 10 Number: 2010
Today's topics:
Stripping Duplicates From Arrays <joeg@optonline.net>
Re: Stripping Duplicates From Arrays <jurgenex@hotmail.com>
Re: Stripping Duplicates From Arrays <trenfro@i-55.com>
Re: Stripping Duplicates From Arrays <djberge@qwest.com>
Re: Telnet client in perl (Chas Friedman)
Total size of all contents of a directory (Leo Dillon)
Re: Total size of all contents of a directory (John J. Trammell)
Re: Total size of all contents of a directory <hillr@ugs.com>
Re: What's wrong with File::Find (Mark Jason Dominus)
Re: What's wrong with File::Find (Randal L. Schwartz)
Re: What's wrong with File::Find <bart.lateur@skynet.be>
Re: What's wrong with File::Find <dtweed@acm.org>
Re: What's wrong with File::Find <nospam-abuse@ilyaz.org>
Re: What's wrong with File::Find <nospam-abuse@ilyaz.org>
Re: What's wrong with File::Find (Mark Jason Dominus)
Re: What's wrong with File::Find <bart.lateur@skynet.be>
Re: What's wrong with File::Find (Mark Jason Dominus)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 25 Oct 2001 15:26:39 GMT
From: "Joe Giordano" <joeg@optonline.net>
Subject: Stripping Duplicates From Arrays
Message-Id: <PaWB7.6375$C7.2592557@news02.optonline.net>
I currently have a script that looks @ a dat file; each line of the dat file
is split on a colon seperating the line into columns. Each column is then
put into an array. I want to take out or ignore the duplicate variables in
the array. I then use each variable in the first array in a loop (So
unfortunatley each time the script uses the same variable I get the same
results. What is the best way to achieve this.
Thanks,
Joe
------------------------------
Date: Thu, 25 Oct 2001 08:57:29 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Stripping Duplicates From Arrays
Message-Id: <3bd8366c@news.microsoft.com>
"Joe Giordano" <joeg@optonline.net> wrote in message
news:PaWB7.6375$C7.2592557@news02.optonline.net...
> I currently have a script that looks @ a dat file; each line of the dat
file
> is split on a colon seperating the line into columns. Each column is then
> put into an array. I want to take out or ignore the duplicate variables in
> the array. I then use each variable in the first array in a loop (So
> unfortunatley each time the script uses the same variable I get the same
> results. What is the best way to achieve this.
perldoc -q duplicate
jue
------------------------------
Date: Thu, 25 Oct 2001 11:22:28 -0700
From: "Tom Renfro" <trenfro@i-55.com>
Subject: Re: Stripping Duplicates From Arrays
Message-Id: <9r9e70$cag$1@news.datasync.com>
Joe,
One possibility is using map() to put the array elements into a hash as
keys. This will eliminate duplication easily. For example,
my @array = (1,2,4,65,2,1,4,2,1);
my %temp = map ( { $_ => 1 } @array );
my @uniquevalues = keys %temp;
The intermediate line is required for the keys() function to see the mapped
hash as a hash and not as list. I can't say if this is the most efficient
method or not.
Hope this helps,
-Tom
"Joe Giordano" <joeg@optonline.net> wrote in message
news:PaWB7.6375$C7.2592557@news02.optonline.net...
> I currently have a script that looks @ a dat file; each line of the dat
file
> is split on a colon seperating the line into columns. Each column is then
> put into an array. I want to take out or ignore the duplicate variables in
> the array. I then use each variable in the first array in a loop (So
> unfortunatley each time the script uses the same variable I get the same
> results. What is the best way to achieve this.
>
> Thanks,
>
> Joe
>
>
------------------------------
Date: Thu, 25 Oct 2001 12:35:45 -0500
From: "Mr. Sunblade" <djberge@qwest.com>
Subject: Re: Stripping Duplicates From Arrays
Message-Id: <70YB7.692$Mw.117463@news.uswest.net>
"Joe Giordano" <joeg@optonline.net> wrote in message
news:PaWB7.6375$C7.2592557@news02.optonline.net...
> I currently have a script that looks @ a dat file; each line of the dat
file
> is split on a colon seperating the line into columns. Each column is then
> put into an array. I want to take out or ignore the duplicate variables in
> the array. I then use each variable in the first array in a loop (So
> unfortunatley each time the script uses the same variable I get the same
> results. What is the best way to achieve this.
>
> Thanks,
>
> Joe
use Set::Array;
$set1 = Set::Array->new(@first_array)->unique;
Regards,
Mr. Sunblade
------------------------------
Date: Thu, 25 Oct 2001 15:16:57 GMT
From: friedman@math.utexas.edu (Chas Friedman)
Subject: Re: Telnet client in perl
Message-Id: <3bd82c0c.1112936390@news.cc.utexas.edu>
On Wed, 24 Oct 2001 21:52:46 +0100, "Scott Bell" <news@scottbell.org>
wrote:
>Does anyone know of a telnet client in perl, I'm not looking for a telnet.pm
>module, an actual perl script.
>
>Thanks.
>
>--
>Scott Bell
>Email: scott@scottbell.org
>
>The content of this message has been certified 100% correct.
>
>
>
I tried to write a telnet client using Net::Telnet, but never could
get anything even close to a full featured result. My main problem was
that using Net::Telnet, you seem to have to always wait for and check
that the response is in some known fixed form. Pehaps I just wasn't
clever enough...if you learn how to write such a client in Perl, I'd
like to see the result. (I imagine it can be done, but it probably
isn't trivial.)
chas
------------------------------
Date: 25 Oct 2001 08:48:19 -0700
From: leo@snorland.co.uk (Leo Dillon)
Subject: Total size of all contents of a directory
Message-Id: <7a35d4fd.0110250748.617b1a0c@posting.google.com>
I was wondering if anyone could help me, I need some code to find the
total size of the contents of any particular directory (including all
subdirectories)
Thanks
------------------------------
Date: Thu, 25 Oct 2001 11:01:51 -0500
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: Total size of all contents of a directory
Message-Id: <slrn9tgdrf.kan.trammell@haqq.el-swifto.com>
On 25 Oct 2001 08:48:19 -0700, Leo Dillon <leo@snorland.co.uk> wrote:
> I was wondering if anyone could help me, I need some code to find the
> total size of the contents of any particular directory (including all
> subdirectories)
>
du -s .
--
My memory is quite unreliable, unless Hunter S. Thompson and I actually
*did* ride the Loch Ness monster through the New York subway system in '97.
------------------------------
Date: Thu, 25 Oct 2001 09:20:16 -0700
From: "Ron Hill" <hillr@ugs.com>
Subject: Re: Total size of all contents of a directory
Message-Id: <3bd83a40$1@usenet.ugs.com>
"Leo Dillon" <leo@snorland.co.uk> wrote in message
news:7a35d4fd.0110250748.617b1a0c@posting.google.com...
> I was wondering if anyone could help me, I need some code to find the
> total size of the contents of any particular directory (including all
> subdirectories)
>
> Thanks
From Tom C
#!/usr/bin/perl -w
use strict;
use File::Find;
@ARGV = ('.') unless @ARGV;
my $sum = 0;
find sub { $sum += -s }, @ARGV;
print "@ARGV contains $sum bytes\n";
Hope it helps
Ron
------------------------------
Date: Thu, 25 Oct 2001 15:23:13 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: What's wrong with File::Find
Message-Id: <3bd82e60.278e$2a9@news.op.net>
In article <3BD79143.66E3AEEA@acm.org>, Dave Tweed <dtweed@acm.org> wrote:
>Mark Jason Dominus wrote:
>> In article <3BD74A01.C3A62D5B@acm.org>, Dave Tweed <dtweed@acm.org> wrote:
>> >Not all anonymous subs are closures.
>> In Perl, all anonymous subs are closures.
>
>I don't think so.
Think what you like.
>perlfaq7:
> Closures are implemented in Perl as anonymous subroutines with lasting
> references to lexical variables outside their own scopes.
>
>and further down:
> The anonymous subroutine returned by add_function_generator() isn't
> technically a closure because it refers to no lexicals outside its
> own scope.
The FAQ is wrong. Tom had a mistaken and overly restrictive notion of
what a closure is. For example:
# (function fn)
#
# If _fn_ is a lambda-expression, then a ``lexical closure'' is
# returned, that is, a function that when invoked will execute the body
# of the lambda-expression in such a way as to observe the rules of
# lexical scoping properly.
(Guy L. Steele, _Common Lisp: The Language (2 ed.)_ p. 115)
Or:
# closure
#
# 1. <programming> In a reduction system, a closure is a data structure
# that holds an expression and an environment of variable bindings in
# which that expression is to be evaluated. The variables may be local
# or global.
(http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?closure)
An anonymous subroutine in Perl is represented by a CV structure. The
CV contains essentially two things: A pointer to the compiled code for
the subroutine (actually two such pointers) and a pointer to the
captured environment in which the subroutine was defined. (The
'pad'.)
When an anonymous subroutine is created, it captures its environment
of definition. Future calls to the subroutine are executed in this
environment, not the new environment that existed at the time of the
call. Because of this, we say that the subroutine is 'closed'.
By captuing its environment in this way, it loses the ability to refer
to any new variables after it has been defined.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: 25 Oct 2001 08:37:07 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: What's wrong with File::Find
Message-Id: <m1adyfviho.fsf@halfdome.holdit.com>
>>>>> "Dave" == Dave Tweed <dtweed@acm.org> writes:
Dave> And I still maintain that "not all anonymous subs are closures" as defined
Dave> in the Perl documentation.
And I second this. If an anon sub doesn't refer to external lexicals,
then you get the same coderef back repeatedly. If it does, you get
a different coderef back. Clearly, the former is returning the same
anon sub each time, but the latter is manufacturing distinct closures.
I posted code to Perlmonks.org showing this a few months ago.
Not all anonymous subroutines are closures (if they don't refer to lexicals)
Not all closures are anonymous subroutines (named closures are the mod_perl problem)
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Thu, 25 Oct 2001 15:56:52 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: What's wrong with File::Find
Message-Id: <19dgtt4evljb3aepvde39okj2mivg9avjm@4ax.com>
Alexander Farber (EED) wrote:
>That's why I think, it's pity that File::Find doesn't support passing
>arguments to the wanted sub - it would be so easy to implement.
I have more serious troubles with File::Find's current implementation.
The main one is that it uses a lexical hash to store the visited links
in. That means that if two threads were to use find or finddepth at the
same time, they'd step all over each other's data.
At least, they should have used a global variable, and local(). That is
precisely the kind of situation it was conceived for.
Having the passed sub access lexicals defined in the surrounding block
is no problem to me. Like this:
{
my $foo = 'xyz';
find sub { $_ eq $foo and print }, @dirs;
}
--
Bart.
------------------------------
Date: Thu, 25 Oct 2001 16:38:09 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: What's wrong with File::Find
Message-Id: <3BD83E8D.4647B60B@acm.org>
Mark Jason Dominus wrote:
> The FAQ is wrong. Tom had a mistaken and overly restrictive notion of
> what a closure is.
You should submit a doc patch.
-- Dave Tweed
------------------------------
Date: Thu, 25 Oct 2001 16:48:56 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: What's wrong with File::Find
Message-Id: <9r9fpo$1vii$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Bart Lateur
<bart.lateur@skynet.be>], who wrote in article <19dgtt4evljb3aepvde39okj2mivg9avjm@4ax.com>:
> I have more serious troubles with File::Find's current implementation.
> The main one is that it uses a lexical hash to store the visited links
> in. That means that if two threads were to use find or finddepth at the
> same time, they'd step all over each other's data.
>
> At least, they should have used a global variable, and local(). That is
> precisely the kind of situation it was conceived for.
You have it exactly backwards. Lexicals are thread-specific, and
local()s (as the name implies ;-) are global. [At least if the
lexical is introduced in the subroutine.]
Ilya
------------------------------
Date: Thu, 25 Oct 2001 16:51:55 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: What's wrong with File::Find
Message-Id: <9r9fvb$1vlp$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Mark Jason Dominus
<mjd@plover.com>], who wrote in article <3bd82e60.278e$2a9@news.op.net>:
> Think what you like.
> An anonymous subroutine in Perl is represented by a CV structure. The
> CV contains essentially two things: A pointer to the compiled code for
> the subroutine (actually two such pointers) and a pointer to the
> captured environment in which the subroutine was defined. (The
> 'pad'.)
Think what you like. But this is b******t. Pad captures the
environment for closures only, not for non-closure anonymous subs.
Ilya
------------------------------
Date: Thu, 25 Oct 2001 17:01:52 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: What's wrong with File::Find
Message-Id: <3bd8457f.29ab$103@news.op.net>
In article <9r9fvb$1vlp$1@agate.berkeley.edu>,
Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
><mjd@plover.com>], who wrote in article <3bd82e60.278e$2a9@news.op.net>:
>> Think what you like.
>
>> An anonymous subroutine in Perl is represented by a CV structure. The
>> CV contains essentially two things: A pointer to the compiled code for
>> the subroutine (actually two such pointers) and a pointer to the
>> captured environment in which the subroutine was defined. (The
>> 'pad'.)
>
>Think what you like. But this is b******t. Pad captures the
>environment for closures only, not for non-closure anonymous subs.
So what? This is an internal optimization that has no effect on the
the execution of any code. The subroutine is still closed.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Thu, 25 Oct 2001 17:16:04 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: What's wrong with File::Find
Message-Id: <v3igtt4sf22c22l5h7ci7u4106qcug78qg@4ax.com>
Ilya Zakharevich wrote:
>You have it exactly backwards. Lexicals are thread-specific, and
>local()s (as the name implies ;-) are global.
Aha.
> [At least if the
>lexical is introduced in the subroutine.]
Well, it's not. See the source for File::Find. Somewhere at the top of
the file, there's
my %SLnkSeen;
which means it's a "global" lexical for the entire file.
--
Bart.
------------------------------
Date: Thu, 25 Oct 2001 17:18:50 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: What's wrong with File::Find
Message-Id: <3bd84979.2a33$fa@news.op.net>
In article <m1adyfviho.fsf@halfdome.holdit.com>,
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "Dave" == Dave Tweed <dtweed@acm.org> writes:
>
>Dave> And I still maintain that "not all anonymous subs are closures" as defined
>Dave> in the Perl documentation.
>
>And I second this. If an anon sub doesn't refer to external lexicals,
>then you get the same coderef back repeatedly. If it does, you get
>a different coderef back. Clearly, the former is returning the same
>anon sub each time, but the latter is manufacturing distinct closures.
This is irrelevant to whether or not those subs are closures.
'Closure' has a specific technical meaning, and this is not it. Folks
are of course free to promulgate this alternative, nonstandard usage
of 'closure', but I don't really see the point. It will just cut us
off from the mainstream of people who are discussing these things
seriously.
Whether Perl returns the same object every time, or a different object
every time, the object is still a closure.
Quoting from Steele again, for example:
In situations where a closure of a lambda-expression over the
same set of bindings may be produced more than once, the
various resulting closures may or may not be 'eq', at the
discretion of the implementation. (p. 117)
This is exactly the situation you are discussing. A
'lambda-expression' is the Lisp equivalent of Perl's anonymous sub
expressions. Two objects are 'eq' in Lisp if they are exactly the
same object. Your code example (and Stas Bekman's in the mod_perl
guide) produces the same closure repeatedly. If a Lisp implementation
did this, folks might point to this paragraph of Steele to say that
this was indeed permissible behavior.
I see no reason to act like Humpty Dumpty and say that the word
'closure' means whatever we want it to. 'Closure' had a well-defined
and well-accepted meaning long before there were closures in Perl, and
we are not doing anyone any favors by using the same word to mean
something different.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
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 2010
***************************************