[25582] in Perl-Users-Digest
Perl-Users Digest, Issue: 7826 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 24 18:10:33 2005
Date: Thu, 24 Feb 2005 15:10:25 -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 Thu, 24 Feb 2005 Volume: 10 Number: 7826
Today's topics:
Re: maximum size of a hash table <postmaster@castleamber.com>
Re: maximum size of a hash table <tassilo.von.parseval@rwth-aachen.de>
Re: OOP Tutorial <jwkenne@attglobal.net>
Re: OOP Tutorial <jwkenne@attglobal.net>
Re: OOP Tutorial <leslievNO@SPAMicoc.co.za>
Re: Read from keyboard <news@chaos-net.de>
Re: Regex combining /(foo|bar)/ slower than using forea <ddunham@redwood.taos.com>
Re: XML:Simple and arrays of hashes (Anno Siegel)
Re: XML:Simple and arrays of hashes <richard.lawrence@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 24 Feb 2005 20:22:34 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: maximum size of a hash table
Message-Id: <Xns9607923D325C6castleamber@130.133.1.4>
Tassilo v. Parseval wrote:
> Also sprach John Bokma:
>> Tad McClellan wrote:
>>
>>> Lee <lskatz@gmail.com> wrote:
>>>
>>>> Does anyone absolutely know the maximum size that a hash table can
>>>> achieve?
>>>
>>> No, because it depends on the particular data being stored and the
>>> size of the memory on your particular machine.
>>
>> Isn't there a limit on the number of bits in the hash?
>> Just curious.
>
> What bits? Perl hashes are not bloom filters so the concepts of bits
> (or the number thereof) isn't involved anywhere.
Ages ago, when I wrote my own hash table stuff (C), I used a function to
calculate the hash code of a string. The result was a 32 bit value, and
hence the number of available slots was 2^32. Of course this doesn't
mean that one can store only 2^32 values, since I handled collision by
using lists. But if you put enough values in such a hash, it will get
more and more inefficient. (Moreover, the pointers used in the list must
be able to address the memory).
So, I was just wondering if Perl has a similar "limit" (ie. the result
of "its" hash function is always n bits).
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Fri, 25 Feb 2005 00:00:45 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: maximum size of a hash table
Message-Id: <slrnd1sn4t.r4.tassilo.von.parseval@localhost.localdomain>
Also sprach John Bokma:
> Tassilo v. Parseval wrote:
>
>> Also sprach John Bokma:
>>> Isn't there a limit on the number of bits in the hash?
>>> Just curious.
>>
>> What bits? Perl hashes are not bloom filters so the concepts of bits
>> (or the number thereof) isn't involved anywhere.
>
> Ages ago, when I wrote my own hash table stuff (C), I used a function to
> calculate the hash code of a string. The result was a 32 bit value, and
> hence the number of available slots was 2^32. Of course this doesn't
> mean that one can store only 2^32 values, since I handled collision by
> using lists. But if you put enough values in such a hash, it will get
> more and more inefficient. (Moreover, the pointers used in the list must
> be able to address the memory).
Naturally, this is what happens. If you have a mapping between a
potentially infinite set into a confined one, collisions are going to
happen. Perl, too, uses lists for buckets with collisions.
> So, I was just wondering if Perl has a similar "limit" (ie. the result
> of "its" hash function is always n bits).
That's the case for any hash function. Yet, the number of those bits (as
you put it) has no bearing on the capacity of a hash. You could use a
hash function that only returns 2bit-wide numbers and still store an
amount of items only limited by the available memory in the hash.
Tassilo
--
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
------------------------------
Date: Thu, 24 Feb 2005 15:33:04 -0500
From: "John W. Kennedy" <jwkenne@attglobal.net>
Subject: Re: OOP Tutorial
Message-Id: <nUqTd.4151$6g2.2883@fe09.lga>
Abigail wrote:
> Leslie Viljoen (leslievNO@SPAMicoc.co.za) wrote on MMMMCXCV September
> MCMXCIII in <URL:news:IuSdnaNqO_naioPfRVn-qg@is.co.za>:
> }} Anno Siegel wrote:
> }} > Paul Uiterlinden <no@spam.nl> wrote in comp.lang.perl.misc:
> }} >
> }} >>Abigail wrote:
> }} >>
> }} >>>$$ http://www.icon.co.za/~mobeus/easyoop.doc.zip (Word)
> }} >>>$$ http://www.icon.co.za/~mobeus/easyoop.sxw.zip (Open Office)
> }} >>>
> }} >>>Oh. Never mind. I don't do Windows.
> }} >>
> }} >>Huh? Open office works on *nix, and zip as well.
> }} >
> }} >
> }} > Abigail didn't say she can't, she said she doesn't.
> }}
> }} Yes but you don't need to do Windows for Open Office. I use Linux almost
> }} exclusively - that's why I created an SXW file. I saved it as a DOC too
> }} in case a Windows person wants to read it.
>
>
> Why would you need open office if you don't do Windows?
Why would you need a C compiler if you don't do MVS?
---
John W. Kennedy
Read the remains of Shakespeare's lost play, now annotated!
http://pws.prserv.net/jwkennedy/Double%20Falshood/index.html
------------------------------
Date: Thu, 24 Feb 2005 15:34:26 -0500
From: "John W. Kennedy" <jwkenne@attglobal.net>
Subject: Re: OOP Tutorial
Message-Id: <FVqTd.4152$k02.537@fe09.lga>
Leslie Viljoen wrote:
> Anno Siegel wrote:
>
>> Paul Uiterlinden <no@spam.nl> wrote in comp.lang.perl.misc:
>>
>>> Abigail wrote:
>>>
>>>> $$ http://www.icon.co.za/~mobeus/easyoop.doc.zip (Word)
>>>> $$ http://www.icon.co.za/~mobeus/easyoop.sxw.zip (Open Office)
>>>>
>>>> Oh. Never mind. I don't do Windows.
>>>
>>>
>>> Huh? Open office works on *nix, and zip as well.
>>
>>
>>
>> Abigail didn't say she can't, she said she doesn't.
>
>
> Yes but you don't need to do Windows for Open Office. I use Linux almost
> exclusively - that's why I created an SXW file. I saved it as a DOC too
> in case a Windows person wants to read it.
Since OpenOffice.org can do it in about three clicks, it might be more
sensible just to publish it as a PDF.
---
John W. Kennedy
"The pathetic hope that the White House will turn a Caligula into a
Marcus Aurelius is as naïve as the fear that ultimate power inevitably
corrupts."
-- James D. Barber (1930-2004).
------------------------------
Date: Thu, 24 Feb 2005 22:56:51 +0200
From: Leslie Viljoen <leslievNO@SPAMicoc.co.za>
Subject: Re: OOP Tutorial
Message-Id: <3Imdnb-IjMILooPfRVn-uw@is.co.za>
Abigail wrote:
> Leslie Viljoen (leslievNO@SPAMicoc.co.za) wrote on MMMMCXCV September
> MCMXCIII in <URL:news:IuSdnaNqO_naioPfRVn-qg@is.co.za>:
> }} Anno Siegel wrote:
> }} > Paul Uiterlinden <no@spam.nl> wrote in comp.lang.perl.misc:
> }} >
> }} >>Abigail wrote:
> }} >>
> }} >>>$$ http://www.icon.co.za/~mobeus/easyoop.doc.zip (Word)
> }} >>>$$ http://www.icon.co.za/~mobeus/easyoop.sxw.zip (Open Office)
> }} >>>
> }} >>>Oh. Never mind. I don't do Windows.
> }} >>
> }} >>Huh? Open office works on *nix, and zip as well.
> }} >
> }} >
> }} > Abigail didn't say she can't, she said she doesn't.
> }}
> }} Yes but you don't need to do Windows for Open Office. I use Linux almost
> }} exclusively - that's why I created an SXW file. I saved it as a DOC too
> }} in case a Windows person wants to read it.
>
>
> Why would you need open office if you don't do Windows?
>
> I'll read plain text, POD, (La)TeX (in order of preference), and I might
> be bothered to start up a reader for a dvi, PostScript, PDF or an HTML
> file. That's about it.
We must bow to the demands of the masses:
http://www.icon.co.za/~mobeus/easyoop.pdf.zip
Can you explain this?
#!/usr/bin/perl -lw
eval {die [[qq [Just another Perl Hacker]]]};;
print
${${${@}}[$#{@{${@}}}]}
[$#{${@{${@}}}
[$#{@{${@}}}]}]
I have been looking at it for a while now and am tired.
------------------------------
Date: Thu, 24 Feb 2005 20:38:49 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: Re: Read from keyboard
Message-Id: <slrnd1sba9.ab8.news@maki.homeunix.net>
Josef Moellers wrote :
> IMHO a much better solution is to avoid redirection of STDIN and require
> the input file to be passed as an argument.
I thought about this solution, too.
But if STDIN is reading from a pipe this will not be possible AFAIK.
If there is a way to handle this, I would be interested in how.
Best Regards
Martin
--
perl -e '$|=1;&p(7.74.117.115.116.32);&s();&p(97.110.111);&p(116.104.101
.114);&s;&p(32.112.101.114.108);&s();&p(32.104.97.99.107.101.114.10);sub
s{sleep 1};sub p(){print "@_"}'
------------------------------
Date: Thu, 24 Feb 2005 20:46:33 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Regex combining /(foo|bar)/ slower than using foreach (/foo/,/bar/) ???
Message-Id: <J2rTd.527$C47.153@newssvr14.news.prodigy.com>
Brian McCauley <nobull@mail.com> wrote:
> complexity. Here's a quick benchmark I threw together to demonstrate
> that one regex is slower than many.
> use strict;
> use warnings;
> use Benchmark;
> my @many = map { "Match$_" } 1 .. 1000;
> my $one = join '|', @many;
> $_ = qr/$_/ for $one, @many;
> my $data = ('random stuff' x 100) . 'Match999';
> timethese 1000 => {
> one => sub { $data =~ $one },
> many => sub { grep { $data =~ $_} @many },
> };
> __END__
> Benchmark: timing 1000 iterations of many, one...
> many: 2 wallclock secs ( 2.76 usr + 0.00 sys = 2.76 CPU) @
> 361.79/s (n=1000)
> one: 33 wallclock secs (32.81 usr + 0.00 sys = 32.81 CPU) @
> 30.48/s (n=1000)
> I think it _is_ true in the general case - although it is possible what
> there exist special cases where it is not.
> Perhaps you can throw one together to illustrate a case where the single
> regex is faster and then make the case for why that case should not be
> considered exceptional.
I went back and found the code, and I guess it was a bit of a special
case, but I didn't think it was at the time. It turns out that my
matches were anchored on the line, and that appears to make a big
difference.
Change
> $_ = qr/$_/ for $one, @many;
to
$one = qr/^($one)/;
$_ = qr/^$_/ for $one, @many;
Now this benchmark isn't quite what my task was doing, but it does show
the big improvement if the match is anchored. I'll have to keep in mind
that the anchor is helping me out in this case. That wasn't something I
noticed when I was working on it initially.
--
Darren Dunham ddunham@taos.com
Senior Technical Consultant TAOS http://www.taos.com/
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
------------------------------
Date: 24 Feb 2005 21:36:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: XML:Simple and arrays of hashes
Message-Id: <cvlhc0$dr$1@mamenchi.zrz.TU-Berlin.DE>
Richard Lawrence <richard.lawrence@gmail.com> wrote in comp.lang.perl.misc:
> Hi there,
>
> Consider the following XML in a file called "data.xml":
>
> <user>
> <name>Frank</name>
> <age>27</age>
> <friends>
> <friend>
> <name>Sue</name>
> <location>London</location>
> </friend>
> <friend>
> <name>Jane</name>
> <location>Paris</location>
> </friend>
> </friends>
> </user>
>
> If I use the following:
>
> #!/usr/bin/perl -w
> use strict;
> use XML::Simple;
> my $user = XMLin("data.xml");
> print "Hi, my name is " . $user->{name};
> print " and I am " . $user->{age} . " years old. ";
> print "My friends are ";
> # Begin horrible code
> my ($key, $value, $k, $v);
> while(($key, $value) = each %{$user->{friends}})
> {
> while(($k, $v) = each %{$value})
> {
> print "$k (who lives in " . $v->{location} . ") and ";
> }
> }
> # End horrible code
> print "thats it!\n";
>
> then I get the intended:
>
> Hi, my name is Frank and I am 27 years old. My friends are Sue (who
> lives in London) and Jane (who lives in Paris) and thats it!
>
> which is great.
>
> However as you have probably noticed from the code, the whole $key,
> $value, $k, $v and nested while's looks really horrible to me and I'm
> sure there is a far better way to do this.
First off, I don't think your xml structure represents very well the
structure of the data. There is a superfluous level in your structure.
But I'm not touching that.
You're looping over keys that function as names of subfields. They
should be addressed through fixed strings, like you do with "name" and
"age". You know what they are, use your knowledge.
Further, don't declare variables ahead of time, declare them when they
are first used. And use reasonable variable names. $k and $v when
$key and $value are already there is indeed horrible.
So, replace you "horrible code" with something like this:
my $friends = $user->{ friends}->{ friend}; # see the extra level?
for my $name ( keys %$friends ) {
my $location = $friends->{ $name}->{ location};
print "$name (who lives in $location) and ";
}
The rest of your code isn't beyond critique either, but I'll let that
go.
Anno
------------------------------
Date: 24 Feb 2005 14:42:08 -0800
From: "Richard Lawrence" <richard.lawrence@gmail.com>
Subject: Re: XML:Simple and arrays of hashes
Message-Id: <1109284928.059610.33630@z14g2000cwz.googlegroups.com>
Anno Siegel wrote:
> First off, I don't think your xml structure represents very well the
> structure of the data. There is a superfluous level in your
structure.
> But I'm not touching that.
Thanks for this. I did wonder about the extra field myself but wasn't
sure whether it was better form to place groups of data (eg. the
friends) in a field of their own or not. I chose to do so and it seems
like that probably wasn't the best - easy to fix though :)
> The rest of your code isn't beyond critique either, but I'll let that
> go.
If you had the time then I would appreciated it if you did critique it.
Otherwise I'll only continue making the same mistakes over and over
again until someone else points them out.
Having said that, I'm assuming its my usage of . to include the
variables because I have no idea how to write:
print "My name is $user->{name}\n";
and actually get it to print correctly? Unfortunately my abilities to
find something on Google or perldoc on how to handle this has failed me
:(
Thanks for your comments,
Richard.
------------------------------
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 7826
***************************************