[27175] in Perl-Users-Digest
Perl-Users Digest, Issue: 9002 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 28 09:05:44 2006
Date: Tue, 28 Feb 2006 06:05:04 -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 Tue, 28 Feb 2006 Volume: 10 Number: 9002
Today's topics:
Re: Import other perl files <ee@eeeeee.org>
Keith Keller - Coward currys favour <rr@rrrrrr.org>
pruning directories by adding hard links <samwyse@gmail.com>
Re: References as Hash Keys, Tree Structures (Newbie) ( <vtatila@mail.student.oulu.fi>
Re: References as Hash Keys, Tree Structures (Newbie) ( <tassilo.von.parseval@rwth-aachen.de>
Re: References as Hash Keys, Tree Structures (Newbie) ( (Anno Siegel)
Regexp - alternate match and grouping <rugowski1spm@nhw.pl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 28 Feb 2006 09:15:13 GMT
From: eeeeee eeeeeeee <ee@eeeeee.org>
Subject: Re: Import other perl files
Message-Id: <BwUMf.3410$972.104188@news20.bellglobal.com>
A. Sinan Unur <1usa@llenroc.ude.invalid> trolled:
> Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us> wrote in
[deleteia]
> Of course. Thanks for catching that.
Please do not respond to Coward Keith Keller.
------------------------------
Date: Tue, 28 Feb 2006 09:14:20 GMT
From: rrrrrr rrrrrrrr <rr@rrrrrr.org>
Subject: Keith Keller - Coward currys favour
Message-Id: <MvUMf.3409$972.104108@news20.bellglobal.com>
Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us> trolled:
[coward's words deleted]
Keith Keller hides his PGP in this group to curry favour with people
he wishes to impress. In alt.os.linux.slackware he advocates using
PGP because he wishes to curry favour with people in that group he
wishes to impress.
Keith Keller is a coward fit for killfiles.
------------------------------
Date: Tue, 28 Feb 2006 14:04:33 GMT
From: Samwyse <samwyse@gmail.com>
Subject: pruning directories by adding hard links
Message-Id: <RLYMf.61599$PL5.12083@newssvr11.news.prodigy.com>
I have a large collection of NTFS files arranged like this:
/desktop-2005-12-01/My Documents/...
/desktop-2006-01-01/My Documents/...
/desktop-2006-02-01/My Documents/...
/laptop-2005-12-01/My Documents/...
/laptop-2006-01-01/My Documents/...
/laptop-2006-02-01/My Documents/...
/server-2005-12-01/My Documents/...
/server-2006-01-01/My Documents/...
/server-2006-02-01/My Documents/...
As one might imagine, there are lots of files duplicated between these
directories. I'd like to hard-link those files to each other,
preferably in a way that reduces the effort required for future pruning.
Before I re-invent the wheel, does anyone know of a package that would
do this? (It doesn't have to be Perl, but I'd prefer Perl over other
solutions.)
If I were to implement a solution myself, I'd probably create a
look-aside directory using MD5 hashses as filenames. Something like this:
#!perl -w
use strict;
use Digest::MD5;
use File::Find;
my $md5 = Digest::MD5->new;
find(\&prune, @ARGV);
sub prune {
open(FH, $_) or return;
binmode FH;
eval {
my $fname = '/md5/' . $md5->addfile(*FH)->hexdigest;
if (-f $fname) {
# I should probably check for MD5 collisions...
unlink $_;
link $fname, $_;
} else {
link $_, $fname;
}
} or $md5->new;
}
Hmmm, that was easy, I think I'll go test it right now.
------------------------------
Date: Tue, 28 Feb 2006 10:02:11 +0200
From: "Veli-Pekka Tätilä" <vtatila@mail.student.oulu.fi>
Subject: Re: References as Hash Keys, Tree Structures (Newbie) (Was: simple pointer operations (newbe))
Message-Id: <du1025$v1u$1@news.oulu.fi>
Tassilo v. Parseval wrote:
> Nowadays they are commonly used for the implementation of inside-out
> objects. Whenever you want to associate some additional data with an
> object, the ability to use it as hash-key is useful.
Ok thanks for the explanation. I did some Googling and seems the term
inside-out object is used primarily in Perl but I might be wrong. Anyway, I
found an article which adviced one to use them for typo-safe attributes
which could be viewed as one form of deffensive programming. URL:
http://www.samag.com/documents/s=9979/sam0603g/0603g.htm
> moduloed hash-code is simply incremented till a free array element has
> been found.
Clever. Though this approach would require you to have a dynamic array,
which is no problem in Perl. K&R used a static array and linked lists,
though, mainly for demonstrational purposes, I suppose.
> I believe the STL internally uses balanced trees for their
> implementation of the 'map' container.
Nice to know. The map in C++ is pretty good, they even offer multimaps
unlike Perl. But then again multimaps are easy to build in Perl so this is
not a problem. Just another distinction between having somthing
out-of-the-box or with a little personal effort. I kind of like the Perl
approach as far as, say strings, go as most of the common utility functions
are rather trivial to build. Still I wish there were more list operations in
the core such as reduce and zip.
> To me the B-tree is not so much a type but some mixture of data-type,
> algorithm and arrangement of data
Depends on the context, I guess.
> Same with linked lists which you rarely find in the core of a language
Except Lisp of course, but that's a bit of an oddity to begin with.
> For me a bucket is first and foremost just a container for something
Ok I thought the use might be hash specific. I stand corrected now, thanks.
--
With kind regards Veli-Pekka Tätilä (vtatila@mail.student.oulu.fi)
Accessibility, game music, synthesizers and programming:
http://www.student.oulu.fi/~vtatila/
------------------------------
Date: Tue, 28 Feb 2006 09:56:33 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: References as Hash Keys, Tree Structures (Newbie) (Was: simple pointer operations (newbe))
Message-Id: <46ihi4Fb1mfsU1@news.dfncis.de>
Also sprach Veli-Pekka Tätilä:
> Tassilo v. Parseval wrote:
>> Nowadays they are commonly used for the implementation of inside-out
>> objects. Whenever you want to associate some additional data with an
>> object, the ability to use it as hash-key is useful.
> Ok thanks for the explanation. I did some Googling and seems the term
> inside-out object is used primarily in Perl but I might be wrong. Anyway, I
> found an article which adviced one to use them for typo-safe attributes
> which could be viewed as one form of deffensive programming. URL:
>
> http://www.samag.com/documents/s=9979/sam0603g/0603g.htm
Yes, inside-out indeed seems to be Perl-centric. On the other hand, it's
nothing that would have been invented by the Perl folks. They are a
variation on the flyweight-pattern where an object is a very lightweight
entity ($dummy in the above article) and it is used to look up the real
data from some static container outside the caller's scope.
Besides avoiding typos, they have some other advantages. One is that
subclassing becomes easier and safer as the access to an object's
innards happens exlusively through accessor methods.
>> moduloed hash-code is simply incremented till a free array element has
>> been found.
> Clever. Though this approach would require you to have a dynamic array,
> which is no problem in Perl. K&R used a static array and linked lists,
> though, mainly for demonstrational purposes, I suppose.
The array behind a hash is almost always dynamic in the sense that it
grows (usually in multiples of two). That usually happens according to a
ratio which gives a trade-off between speed and memory. The lower the
ratio, the faster the hash becomes but the more memory it will eat:
if ($self->num_pairs / $self->num_buckets > 0.75) {
$self->num_buckes <<= 1;
$self->resize();
$self->rehash_stored_pairs();
}
The increment of the hash-code happens modulo the array-length so if the
right edge of the array has been reached, it wraps around and starts
from the beginning.
>> I believe the STL internally uses balanced trees for their
>> implementation of the 'map' container.
> Nice to know. The map in C++ is pretty good, they even offer multimaps
> unlike Perl. But then again multimaps are easy to build in Perl so this is
> not a problem. Just another distinction between having somthing
> out-of-the-box or with a little personal effort. I kind of like the Perl
> approach as far as, say strings, go as most of the common utility functions
> are rather trivial to build. Still I wish there were more list operations in
> the core such as reduce and zip.
These are in List::Util and List::MoreUtils respectively. Again it's a
trade-off between providing functionality in the core of a language and
bloat caused by too many keywords. I think PHP has a few hundred
keywords and certainly screwed up on that front. Perl might lack a few
but at least a normal human can learn all the keywords by heart.
>> Same with linked lists which you rarely find in the core of a language
> Except Lisp of course, but that's a bit of an oddity to begin with.
But even LISP uses them only behind the scenes to implement the lists
the programmer sees and uses, right? Not that I would know much about
LISP anyway...
Tassilo
--
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
------------------------------
Date: 28 Feb 2006 12:03:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: References as Hash Keys, Tree Structures (Newbie) (Was: simple pointer operations (newbe))
Message-Id: <du1e68$apt$1@mamenchi.zrz.TU-Berlin.DE>
Tassilo v. Parseval <tassilo.von.parseval@rwth-aachen.de> wrote in comp.lang.perl.misc:
> Also sprach Veli-Pekka Tätilä:
> > Tassilo v. Parseval wrote:
> >> Nowadays they are commonly used for the implementation of inside-out
> >> objects. Whenever you want to associate some additional data with an
> >> object, the ability to use it as hash-key is useful.
> > Ok thanks for the explanation. I did some Googling and seems the term
> > inside-out object is used primarily in Perl but I might be wrong. Anyway, I
> > found an article which adviced one to use them for typo-safe attributes
> > which could be viewed as one form of deffensive programming. URL:
> >
> > http://www.samag.com/documents/s=9979/sam0603g/0603g.htm
>
> Yes, inside-out indeed seems to be Perl-centric. On the other hand, it's
> nothing that would have been invented by the Perl folks. They are a
> variation on the flyweight-pattern where an object is a very lightweight
> entity ($dummy in the above article) and it is used to look up the real
> data from some static container outside the caller's scope.
>
> Besides avoiding typos, they have some other advantages. One is that
> subclassing becomes easier and safer as the access to an object's
> innards happens exlusively through accessor methods.
As a consequence, inside-out objects don't suffer from the type-dependency
other perl objects show. A standard hash class can only inherit easily
from another hash class, and only another hash class can easily inherit
from it. In contrast, any type of class can inherit from any number of
inside-out classes, and an inside-out class can inherit from one
foreign (non-inside-out) class. Multiple inheritance *from* foreign
classes involves the usual trickery, often basing inheritance on a
has-a relation.
The other big advantage of inside-out classes is that different classes
have separate lexical name spaces for their fields (properties, attributes,
object variables, whatever). Typo-safety is only a small side-aspect
of this. The main advantage is that classes don't have to co-ordinate
their internal field names (a fundamental breach of privacy), as is the
case with standard hash classes.
The reason why inside-out classes are such a big deal in Perl is that
other OO languages don't have different types of object (scalar, array,
hash, etc.) but implement only one. Also, name space separation is
usually built into a typical OO language and doesn't have to be
implemented by the user. So this particular type of light-weight
object doesn't have general advantages over other objects the way
it does in Perl.
If I had my way, I'd call what is known as inside-out classes simply
"free classes". Inside-out, besides being a mouthful, describes the
implementation in contrast to the standard implementation of hash
classes, which it has set out to make obsolete. That's bad politics.
Mathematicians call a group "free" when it has generators that are
independent of each other, without troublesome algebraic relations.
Similarly, inside-out classes are free from troublesome interrelations
of name spaces and object types.
Having free classes would make Perl the only language that has free
modules (another related mathematical term). But, as we say in
German, "Der Zug ist abgefahren" (That train is long gone).
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Tue, 28 Feb 2006 13:49:14 +0100
From: Witold Rugowski <rugowski1spm@nhw.pl>
Subject: Regexp - alternate match and grouping
Message-Id: <du1gsb$nd$1@news-pa1.hpl.hp.com>
Hi!
I need to do some grouping in regexp's but data can have different format. I'm trying to gather some data from syslog servers. I'm trying to extract client hostname (from FreeBSD syslog) or client's ip (from Webtrends syslog).
First ones looks like:
Feb 28 00:00:00 HOSTNAME Feb 28 2006 01:00:00 HOSTNAME : %PIX-6-305011 [cut]
And from Webtrends:
WTsyslog[2006-02-26 23:59:59 ip=IP_ADDRESS pri=6] <14>Feb 26 2006 23:59:59: %PIX-6-302016: [cut]
Currently I'm matching it with:
/(?:([\w\d\-\_\.]*) |ip=([.\d]*).*?)(\w{3} \d{2} \d{4} \d{2}:\d{2}:\d{2})[\w\d\-\_\.: ]*?%PIX[and more]/
But this means that $1 or $2 is defined, depending on input data format. Is some better way to do it? Better for me means that $1 always is HOSTNAME or IP address and $2 is always date...
--
Witold Rugowski
rugowski_at_nhw_pl
http://nhw.pl/blg/
------------------------------
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 9002
***************************************