[27079] in Perl-Users-Digest
Perl-Users Digest, Issue: 8973 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 19 18:06:08 2006
Date: Sun, 19 Feb 2006 15: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 Sun, 19 Feb 2006 Volume: 10 Number: 8973
Today's topics:
Pattern Matching on Case <dburchm1@verizon.net>
Re: Pattern Matching on Case <1usa@llenroc.ude.invalid>
Re: Speeding up <gamo@telecable.es>
Re: Speeding up <uri@stemsystems.com>
Re: Speeding up <gamo@telecable.es>
Re: Speeding up <uri@stemsystems.com>
Re: Speeding up <abigail@abigail.nl>
Re: Speeding up <uri@stemsystems.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 19 Feb 2006 18:59:50 GMT
From: "DANIEL BURCH" <dburchm1@verizon.net>
Subject: Pattern Matching on Case
Message-Id: <Ge3Kf.3027$GQ.2625@trnddc03>
I have a file that apparently had html tags stripped out of it, or
something, but no space characters added to replace the tags so it ended up
with a lot of words run together like "ExplosionThis". In almost all cases
there is a lower case letter followed by an upper case letter. I am trying
to figure out a substitution statement that would separate them, but I'm not
sure what would work. Maybe something like
s/*[a-z][A-Z]*/*[a-z] [A-Z]*/g;
but I don't have a clue if that is even close to working or if it will give
me an "a" at the end and beginning of the words. Any help would be greatly
appreciated.
------------------------------
Date: Sun, 19 Feb 2006 19:11:52 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Pattern Matching on Case
Message-Id: <Xns976F9086B7982asu1cornelledu@127.0.0.1>
"DANIEL BURCH" <dburchm1@verizon.net> wrote in
news:Ge3Kf.3027$GQ.2625@trnddc03:
> I have a file that apparently had html tags stripped out of it, or
> something, but no space characters added to replace the tags so it
> ended up with a lot of words run together like "ExplosionThis". In
> almost all cases there is a lower case letter followed by an upper
> case letter. I am trying to figure out a substitution statement that
> would separate them, but I'm not sure what would work. Maybe
> something like
>
> s/*[a-z][A-Z]*/*[a-z] [A-Z]*/g;
I am curious: What do you think this does?
Here is a quick and dirty attempt based on your vague specification, and
nothing else. You might want to post some real code along with data
after reading the posting guidelines for this group.
#!/usr/bin/perl
use strict;
use warnings;
my $text;
{
local $/;
$text = <DATA>;
}
$text =~ s{\.\s+}{}g;
$text =~ s{([[:lower:]])([[:upper:]])}{$1\. $2}g;
print "$text\n";
__DATA__
I have a file that apparently had html tags stripped out of it,
or something, but no space characters added to replace the tags
so it ended up with a lot of words run together like "ExplosionThis."
In almost all cases there is a lower case letter followed by an
upper case letter. I am trying to figure out a substitution
statement that would separate them, but I'm not sure what would
work. Maybe something like
Notice the mess this makes of "ExplosionThis".
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Sun, 19 Feb 2006 17:35:43 +0100
From: gamo <gamo@telecable.es>
Subject: Re: Speeding up
Message-Id: <Pine.LNX.4.64.0602191722240.524@jvz.es>
On Sun, 19 Feb 2006, Abigail wrote:
> gamo (gamo@telecable.es) wrote on MMMMDLV September MCMXCIII in
September?
...
> The obvious improvement is to stop testing as soon as one test
> fails, as you only want to do something if all cases match.
> You'd have to benchmark with data that's relevant for your application
> (and test both data that matches *and* data that fails).
Ok, but I can't test all the real problem, which ranges varies too much.
>
> One way of writing would be:
>
>
> if (index ($k => $res [0]) >= 0 &&
> index ($k => $res [1]) >= 0 &&
> index ($k => $res [2]) >= 0 &&
> index ($k => $res [3]) >= 0 &&
> index ($k => $res [4]) >= 0 &&
> index ($k => $res [5]) >= 0 &&
> index ($k => $res [6]) >= 0 &&
> index ($k => $res [7]) >= 0) {
> ...
> }
>
>
> For engineering purposes not the best, but you lose the overhead of
> a loop (and no additional scopes to enter), and gain the benefit of
> skipping the rest of the tests if one fails.
>
>
>
> Abigail
> --
> perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
>
Thank you very much. We have a winner
Rate for grep if
for 163424/s -- -36% -43%
grep 254970/s 56% -- -11%
if 285632/s 75% 12% --
The problem as I said before is not yet solved.
Reversing the matrix of $k only speed up initial calculations.
Thus, it's neccesary to optimize this part of code, which is
executed millions and millions times.
Best regards
------------------------------
Date: Sun, 19 Feb 2006 15:16:39 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Speeding up
Message-Id: <x7accn6r4o.fsf@mail.sysarch.com>
>>>>> "g" == gamo <gamo@telecable.es> writes:
g> I want to speed up this code:
g> $kk=0;
g> for (0..7){
g> $kk++ if (index($k,$res[$_]) >=0);
g> }
g> if ($kk==8){
g> ...
my main suggestion is to loop over the @res values directly and not
index to get them. you don't seem to really need the value of $kk (and
it will never get to 8 with a 0 .. 7 loop so that is a bug!)
if you must have a check for failure you could use a flag (eww) or wrap
the test in a sub like this (untested):
sub check_for_foolish_value {
my $text = shift ;
foreach my $foolish_value ( @_ ) {
return $foolish_value if
index( $text, $foolish_value ) >= 0 ;
}
return ;
}
i bet even with the sub overhead it will be faster than all that array
indexing. but i could be wrong so someone else should benchmark it.
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: Sun, 19 Feb 2006 21:30:44 +0100
From: gamo <gamo@telecable.es>
Subject: Re: Speeding up
Message-Id: <Pine.LNX.4.64.0602192127140.656@jvz.es>
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
--8323328-1763538995-1140381044=:656
Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE
On Sun, 19 Feb 2006, Uri Guttman wrote:
>>>>>> "g" =3D=3D gamo <gamo@telecable.es> writes:
>
> g> I want to speed up this code:
>
> g> $kk=3D0;
> g> for (0..7){
> g> $kk++ if (index($k,$res[$_]) >=3D0);
> g> }
> g> if ($kk=3D=3D8){
> g> =09=09...
>
> my main suggestion is to loop over the @res values directly and not
That could be fine.
> index to get them. you don't seem to really need the value of $kk (and
> it will never get to 8 with a 0 .. 7 loop so that is a bug!)
>
It is not. From 0 to 7 there are 8 evaluations.
> if you must have a check for failure you could use a flag (eww) or wrap
> the test in a sub like this (untested):
>
> =09sub check_for_foolish_value {
>
> =09=09my $text =3D shift ;
>
> =09=09foreach my $foolish_value ( @_ ) {
>
> =09=09=09return $foolish_value if
> =09=09=09=09index( $text, $foolish_value ) >=3D 0 ;
> =09=09}
>
> =09=09return ;
> =09}
>
> i bet even with the sub overhead it will be faster than all that array
> indexing. but i could be wrong so someone else should benchmark it.
>
> uri
>
> --=20
> Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems=
=2Ecom
> --Perl Consulting, Stem Development, Systems Architecture, Design and Cod=
ing-
> Search or Offer Perl Jobs ---------------------------- http://jobs.perl=
=2Eorg
>
Best regards.
--=20
http://www.telecable.es/personales/gamo/
S=F3lo hay 10 tipos de personas, las que saben binario y las que no
GED/GB d+ s+:+ a C++ U+++ P+++ L++ E---- W++ N++ o K+ w O+ M- V
PS++ PE++ Y PGP+ t 5-- X+ R-- tv-- b++ DI++ D+ G- e+++ h+ r-- z
perl -e 'print 111_111_111**2,"\n";'
--8323328-1763538995-1140381044=:656--
------------------------------
Date: Sun, 19 Feb 2006 16:39:59 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Speeding up
Message-Id: <x764nb6n9s.fsf@mail.sysarch.com>
>>>>> "g" == gamo <gamo@telecable.es> writes:
g> $kk=0;
g> for (0..7){
g> }
g> if ($kk==8){
g> ...
>> index to get them. you don't seem to really need the value of $kk (and
>> it will never get to 8 with a 0 .. 7 loop so that is a bug!)
>>
g> It is not. From 0 to 7 there are 8 evaluations.
i never said the number of evaluations wasn't 8. i said $kk will never
be 8 so the if ($kk==8) will always fail. that is a bug. a classic off
by one or picket fence error. in a c style for loop, $kk would probably
become 8 so it would fail of the loop. in foreach ( $n .. $m ) loops the
loop iterator gets $m as its last value.
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: 19 Feb 2006 21:47:45 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Speeding up
Message-Id: <slrndvhps1.1fv.abigail@alexandra.abigail.nl>
Uri Guttman (uri@stemsystems.com) wrote on MMMMDLV September MCMXCIII in
<URL:news:x764nb6n9s.fsf@mail.sysarch.com>:
$$ >>>>> "g" == gamo <gamo@telecable.es> writes:
$$
$$ g> $kk=0;
$$ g> for (0..7){
$$ g> }
$$ g> if ($kk==8){
$$ g> ...
$$
$$ >> index to get them. you don't seem to really need the value of $kk (and
$$ >> it will never get to 8 with a 0 .. 7 loop so that is a bug!)
$$ >>
$$
$$ g> It is not. From 0 to 7 there are 8 evaluations.
$$
$$
$$ i never said the number of evaluations wasn't 8. i said $kk will never
$$ be 8 so the if ($kk==8) will always fail. that is a bug. a classic off
$$ by one or picket fence error. in a c style for loop, $kk would probably
$$ become 8 so it would fail of the loop. in foreach ( $n .. $m ) loops the
$$ loop iterator gets $m as its last value.
#!/usr/bin/perl
use strict;
use warnings;
no warnings 'syntax';
my $kk = 0;
for (0 .. 7) {
$kk ++;
}
if ($kk == 8) {
print "uri is wrong\n";
}
__END__
uri is wrong
Abigail
--
:$:=~s:$":Just$&another$&:;$:=~s:
:Perl$"Hacker$&:;chop$:;print$:#:
------------------------------
Date: Sun, 19 Feb 2006 17:05:42 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Speeding up
Message-Id: <x7y80757ih.fsf@mail.sysarch.com>
>>>>> "A" == Abigail <abigail@abigail.nl> writes:
A> for (0 .. 7) {
A> $kk ++;
A> }
A> if ($kk == 8) {
A> print "uri is wrong\n";
A> }
A> __END__
A> uri is wrong
blech, i forgot about the $kk++ in the OP's code. it's been a couple of
days since i saw it.
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: 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 8973
***************************************