[26222] in Perl-Users-Digest
Perl-Users Digest, Issue: 8407 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 12 09:06:31 2005
Date: Mon, 12 Sep 2005 06:05: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, 12 Sep 2005 Volume: 10 Number: 8407
Today's topics:
Re: Can a Perl Programmer Pick up PHP quickly? nospam@geniegate.com
Re: How to redirect stderr to C lang function (Anno Siegel)
Re: Installing packages <iss025@bangor.ac.uk>
Re: IPC::Shareable Problem with multidimentional hash <sppNOSPAM@libello.com>
Re: Space (\s) count problem (Anno Siegel)
Re: Space (\s) count problem <no@email.com>
Re: Space (\s) count problem <"h.v.niekerk at hccnet.nl">
Re: Space (\s) count problem <no@email.com>
Re: Space (\s) count problem <tadmc@augustmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 12 Sep 2005 12:43:32 GMT
From: nospam@geniegate.com
Subject: Re: Can a Perl Programmer Pick up PHP quickly?
Message-Id: <Lucy1126526740103830x743cf4@air.tunestar.net>
In: <Xns96CE386A3BA4Ccastleamber@130.133.1.4>, John Bokma <john@castleamber.com> wrote:
>btw: check out:
>
>use base CLASS
See, this, along with 'our()', 'local()', \*FILE_HANDLE sub() -vs - &sub()
and probably many others is part of why PHP is easier to learn than perl.
NOTE: easier != better.
In perl, you can use @ISA or use base. (and some weird stuff involving %FIELDS)
PHP hasn't gotten old enough to pick up these kinds of warts. (and BTW, I
like the warts thank you! :-) )
Used to be you'd call a sub like this &subroutine() which is how I learned
it.
The whole 'more than one way to do it' is nice, but it does make perl harder
to learn.
For a Perl coder, PHP is simply a matter of sitting down and writing. (and
probably hating it because of the way it hampers ones sense of creativity)
>Wrt $AUTOLOAD: maybe rtfm, and it becomes clear how useful it is. You
>*don't* have to use it, but it makes life easier.
>
>> just
>> classes, methods and inheritance, the way they're meant to be.
>
>*sniggers* you are talking about PHP now are you?
PHP has something-to-the-effect-of classes. No real name spaces though.
Seems to me, PHP5 is looking up toward 'java'. Has interfaces and all that
jazz. (still no inner classes though)
While perl has had 'die' for years, PHP only recently picked up exceptions.
Naturally, a language with fewer features is going to be easier to learn. (and
probably parse much faster too)
>> PHP functions are, on the other hand, well documented,
>
>*sniggers*, sure. Maybe you misunderstand the word well.
PHP is pretty well documented. I don't think it's as documented as perl
though. Problem with perl is it's *too well* documented.
>> secrets and tricks that can be learned only through the word of mouth
>> and bizarre mechanisms like "tie" is much, much harder to learn.
>
>What is bizarre about tie? Which part do you not understand? It's
>nothing more then being able to override some methods on a type of
>variable.
tie is rather hackish, you can admit it, I won't say anything. (hackish
and quite useful at times.)
BTW, speaking of 'tie' and undocumented.. PHP also has stuff like 'tie'
but they don't call it as such. It's the kind of thing that is very hard
to learn about compared to perl because it isn't as well documented as perl
is. (they call it 'spl' or some-such, the idea being to implement a standard
interface) Trying to learn about it is rather tough because you have
to know what to look for. I suspect perl is easier to learn in that regard
at least.
Jamie
--
http://www.geniegate.com Custom web programming
guhzo_42@lnubb.pbz (rot13) User Management Solutions
------------------------------
Date: 12 Sep 2005 08:01:32 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to redirect stderr to C lang function
Message-Id: <dg3cks$rfk$1@mamenchi.zrz.TU-Berlin.DE>
Keywords: Perl, stderr
Lukas P <luki@NOSPAMsdf-eu.org> wrote in comp.lang.perl.misc:
> Hello,
>
> I am currently trying to figure out how to redirect all Perl error
> messages to my own logging function. The Perl interpreter is embedded in
> my app (written in C), which means that I can modify even the interpreter
> itself.
>
> I have found several ways to do it, but none of them seems to be
> "proper" way.
The third method you tried is the proper one.
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: Mon, 12 Sep 2005 10:47:59 +0100
From: "P.R.Brady" <iss025@bangor.ac.uk>
Subject: Re: Installing packages
Message-Id: <43254ECF.4010905@bangor.ac.uk>
Bob Walton wrote:
> P.R.Brady wrote:
>
>> I've installed a few packages onto my XP office system using ppm which
>> has proved very simple. Internet speed has not been a concern as it's
>> 100 Mbit/s.
>> I now want to transfer these to my system at home where Internet
>> speeds are very low. Can I transfer these from my office system via
>> CD or memory stick? Which files do I need to copy across/what is the
>> procedure?
>>
>> Regards
>> Phil
>
>
> You can go to:
>
> http://ppm.activestate.com/PPMPackages/zips/8xx-builds-only/Windows/
>
> and download the .zip files of the packages you want, and burn them to
> CD or whatever. Then unzip them to a directory, and use ppm's
> "repository add" command to add that directory, like:
>
> C:>ppm
> ppm> repository add name c:\temp\whatever
>
> Turn off the respositories you don't want (if any) using the "repository
> off" command. Then issue ppm stuff as usual.
>
> HTH.
Great! Thanks.
Phil
--
Phil Brady
Information Services
University of Wales, Bangor
Adeilad Deiniol
Deiniol Rd
Bangor LL57 2UX
Tel +44 (0)1248 382960
Fax +44 (0)1248 383826
P.R.Brady@bangor.ac.uk
------------------------------
Date: Mon, 12 Sep 2005 11:50:24 +0200
From: =?ISO-8859-1?Q?S=E9bastien_Cottalorda?= <sppNOSPAM@libello.com>
Subject: Re: IPC::Shareable Problem with multidimentional hash
Message-Id: <43254f5e$0$11597$626a14ce@news.free.fr>
xhoster@gmail.com a écrit :
> Sébastien_Cottalorda <scottalorda@libello.com> wrote:
>
>>xhoster@gmail.com wrote:
>>
>>>Sébastien_Cottalorda <scottalordaNOSPAM@libello.com> wrote:
>>>
>>>
>>>>Hi all,
>>>>
>>>>I need to use that kind of shared hash:
>>>>%shared_hash = (
>>>> '123456' => {
>>>> 'bla' => 123,
>>>> 'bli' => 465,
>>>> ect ...
>>>> },
>>>> ect ...
>>>>);
>>>>
>>>>with about 500 primary keys.
>>>>When I "feed" the %shared_hash, I note that the system create as many
>>>>shared segment and semaphore than there are primary keys.
>>>
>>>
>>>Yes. This fact is documented.
>>
>>Where ... ?
>>I understand limits but not the manner it stores datas like hashes.
>
>
> It is not the hashes, it is the references to the hashes:
>
> REFERENCES
>
> When a reference to a non-tied scalar, hash, or array is assigned to a
> tie()d variable, IPC::Shareable will attempt to tie() the thingy being
> referenced[4] ....
> Secondly, since a new shared memory segment is created for each thingy
> being referenced, the liberal use of references could cause the system to
> approach its limit for the total number of shared memory segments allowed.
>
OK, I understand now.
>
>>>You could try using Storable or Data::Dumper to collapse the inner
>>>structures into flat strings for storage.
>>>
>>>Xho
>>
>>I've read, re-read, re-re-read the perldoc IPC::Shareable : It seems to
>>already use Storable to store hash structure.
>
>
> It uses Storable to store the top level hash structure. It also uses
> Storable to store each sub-hash too, but it does each of those in a
> different shmem segment. If you preemptively use Storable on the inner
> hashes, so that they are just strings and not hashrefs by the time they get
> stuck in the main hash, then IPC::Shareable would just store them as
> strings in the main shmem segment.
>
>
>>Concerning Data::Dumper, I don't understand anything (maybe it's me ;-) )
>>I don't understand how I can use that module to store and manipulate
>>hash of hash in a share structure.
>
>
> You use Data::Dumper the same way you use Storable, but the thawing is
> more awkward.
>
>
>>If you have an exemple, I'll apreciate a lot.
>
>
> It ain't pretty, but I don't think using shared memory ever is pretty.
>
>
> my ($i,$j);
> for $i (1 .. 300){
> my %x;
> for $j (1..3){
> $x{$j} = "fall";
> }
> $colours{$i} = freeze \%x;
> }
> print "Charged - Press a key to continue -\n";
> my $e=<STDIN>;
> foreach $i ( keys %colours){
> print "$i => \n";
> my $x=thaw $colurs{$i};
> foreach $j (keys %$x){
> print " $x{$j}\n";
> }
> }
> exit;
>
> Note that this won't be very fast, because it is freezing and thawing the
> entire data structure just to access one part of it. I suspect that that
> is why Shareable was implemented the way it was (using seperate segments
> for each piece) in the first place.
>
> Shared memory is not one of the hard things which Perl has made easy.
>
> Xho
>
Thanks a lot for your help.
I'll try your solution.
Maybe I've another one:
My complex hash %complex_hash is particular, it's like this:
%complex_hash =(
'code1' => {
"Startdate" => ...,
"Enddate" => ...,
...
total = about 20 keys
},
'code2' => {
"Startdate" => ...,
"Enddate" => ...,
...
total = about 20 keys
},
...
'code300' => {
"Startdate" => ...,
"Enddate" => ...,
...
total = about 20 keys
}
);
If I change it like this:
%complex_hash = (
"StarDate" => {
'code1' => ...,
'code2' => ...,
...
'code300' => ...
},
"Enddate" => {
'code1' => ...,
'code2' => ...,
...
'code300' => ...
},
...
about 20 primary keys
);
I'll solve a few my problem because now, it will create about 20-21
segments each of them containing all codes.
What do you think of that ?
Sebastien
------------------------------
Date: 12 Sep 2005 09:06:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Space (\s) count problem
Message-Id: <dg3ge4$1h4$1@mamenchi.zrz.TU-Berlin.DE>
Brian Wakem <no@email.com> wrote in comp.lang.perl.misc:
> John Bokma wrote:
>
> > Huub <"h.v.niekerk at hccnet.nl"> wrote:
> >
> >> Hi,
> >>
> >> I want to read the white space character, but it doesn't work. Sofar I
> >> have this code for the actual reading.
> >
> > You want to count, not read:
> >
> > perldoc -q count
> >
>
>
> A few months ago I had to write something to count the number of times a
> certain string was found in another string. The script would have to do it
> 10s of thousands of times in each execution on strings of ~3KB.
> It had to be fast, and after much benchmarking, I found the fastest method
> (on my machine anyway) is one not in the faq, but to substitute the string
> with itself and count the number of successes.
>
> $matches += ($string =~ s!\Q$kw!$kw!g);
>
> Which was ~ 12% faster than anything in faq if I remember correctly.
>
> Why this is faster than :-
>
> $matches++ while $string =~ m!\Q$kw!g;
>
> I have no idea.
An alternative that avoids the unnecessary substitution is
$matches = () = $string =~ m!\Q$kw!g;
These do all their counting internally in a C level loop. The while-loop
is Perl level, hence slower.
The only problem with this perfectly plausible explanation is that
benchmarks don't support it. I'm finding the substitution and the
global matching solution in the same ballpark but the explicit loop
beats them by a factor of two.
Anno
#!/usr/bin/perl
use strict; $| = 1;
use Benchmark qw( cmpthese);
our $string = ' xxx xxx xx xxx xxx xxxxxxxx x'
x 100;
our $kw = 'xxx';
goto bench;
my $n1 = 0; $n1 ++ while $string =~ /$kw/g;
my $n2 = $string =~ s!\Q$kw!$kw!g;
my $n3 = () = $string =~ m!\Q$kw!g;
print "$n1, $n2, $n3 (600)\n";
exit;
bench:
cmpthese -3, {
loop => 'my $m1 = 0; $m1 ++ while $string =~ /$kw/g;',
subst => 'my $m2 = $string =~ s!\Q$kw!$kw!g;',
match => 'my $m3 = () = $string =~ m!\Q$kw!g;',
};
--
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: Mon, 12 Sep 2005 10:45:54 +0100
From: Brian Wakem <no@email.com>
Subject: Re: Space (\s) count problem
Message-Id: <3ol12iF6cdovU1@individual.net>
Anno Siegel wrote:
> An alternative that avoids the unnecessary substitution is
>
> $matches = () = $string =~ m!\Q$kw!g;
That's about 50% slower than substitution on my machine.
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: Mon, 12 Sep 2005 13:57:35 +0200
From: Huub <"h.v.niekerk at hccnet.nl">
Subject: Re: Space (\s) count problem
Message-Id: <43256c81$0$764$3a628fcd@reader10.nntp.hccnet.nl>
Joe Smith wrote:
> Huub wrote:
>
>> $spatie++ if m/\s/m
>>
>> The line to be read is: dit is een test voor TIRCIN
>
>
> You used the /m option instead of /g.
> You did not include any code to repeat matches.
>
> $spatie++ while m/\s/g;
>
> It is recommended to use tr/// for counting characters.
> -Joe
I can't find tr///. Apart from that, I want to actually read each
character (into an array) until the white space is reached. So if the
array is e.g. @woord1(1..$max1), does @woord1[1] = m/\w/g fill that
element of the array with the read character?
------------------------------
Date: Mon, 12 Sep 2005 13:14:43 +0100
From: Brian Wakem <no@email.com>
Subject: Re: Space (\s) count problem
Message-Id: <3ol9pjF6dv79U1@individual.net>
Huub <"h.v.niekerk at hccnet.nl"> wrote:
> I can't find tr///. Apart from that, I want to actually read each
> character (into an array) until the white space is reached. So if the
> array is e.g. @woord1(1..$max1), does @woord1[1] = m/\w/g fill that
> element of the array with the read character?
That's still a rather cryptic explanation, but it sounds like you should be
using 'split'.
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: Mon, 12 Sep 2005 07:53:29 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Space (\s) count problem
Message-Id: <slrndiaui9.r2a.tadmc@magna.augustmail.com>
Huub <> wrote:
> Joe Smith wrote:
>> Huub wrote:
>>
>>> $spatie++ if m/\s/m
>>>
>>> The line to be read is: dit is een test voor TIRCIN
>>
>>
>> You used the /m option instead of /g.
>> You did not include any code to repeat matches.
>>
>> $spatie++ while m/\s/g;
>>
>> It is recommended to use tr/// for counting characters.
> I can't find tr///.
perldoc -f tr
tr/// The transliteration operator. Same as "y///". See perlop.
perldoc perlop
> Apart from that, I want to actually read each
> character (into an array) until the white space is reached.
Then you misled us with your poor choice of Subject header.
> So if the
> array is e.g. @woord1(1..$max1),
Array indexes start at zero in Perl.
Arrays in Perl are indexed inside of [square] brackets, not (parenthesis).
Please post Real Perl here.
> does @woord1[1] = m/\w/g fill that
> element of the array with the read character?
What happened when you tried it?
@woord1 = m/\G\S/g; # match & save the leading non-space characters
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 8407
***************************************