Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)

7 views
Skip to first unread message

Michele Dondi

unread,
Sep 13, 2007, 6:36:27 AM9/13/07
to
Just copying here from: <http://perlmonks.org/?node_id=638552>
(Please check the thread for other interventions. BTW: I'm *not* the
author of the post...)


I have two very long (>64k) strings of equal lengths - $s1 and $s2.
They are strings of bytes, meaning that any value from chr(0) to
chr(255) is legal. $s2, however, will not have any chr(0). $s1 may or
may not have any. What I need to do is look at each byte in $s1 and if
it is chr(0), replace it with the corresponding byte in $s2. So,
something like the following code:

sub foo {
my ($s1, $s2) = @_;

my @s1 = split //, $s1;
my @s2 = split //, $s2;

foreach my $idx ( 0 .. $#s1 ) {
if ( $s1[$idx] eq chr(0) ) {
$s1[$idx] = $s2[$idx];
}
}

return join '', @s1;
}

foo() could return the resulting string or it could modify $s1 in
place. If foo() returns $s1, I'm going to be doing $s1 = foo( $s1, $s2
); in all cases.

Here's what I've got so far, including Benchmark harness. Whoever
comes up with the fastest version earns a meter of beer from me
whenever we see each other.

#!/usr/bin/perl

use 5.6.0;

use strict;
use warnings FATAL => 'all';

use Benchmark qw( cmpthese );

my $s1 = join '', (do_rand(1) x 100_000);
my $s2 = join '', (do_rand(0) x 100_000);

cmpthese( -2, {
'split1' => sub { my $s3 = split1( $s1, $s2 ) },
'substr1' => sub { my $s3 = substr1( $s1, $s2 ) },
});

sub split1 {
my ($s1, $s2) = @_;

my @s1 = split //, $s1;
my @s2 = split //, $s2;

foreach my $idx ( 0 .. $#s1 ) {
if ( $s1[$idx] eq chr(0) ) {
$s1[$idx] = $s2[$idx];
}
}

return join '', @s1;
}

sub substr1 {
my ($s1, $s2) = @_;

for my $idx ( 0 .. length($s1) ) {
if ( substr($s1,$idx,1) eq chr(0) ) {
substr($s1, $idx, 1) = substr($s2, $idx, 1);
}
}

return $s1;
}

# This makes sure that $s1 has chr(0)'s in it and $s2 does not.
sub do_rand {
my $n = (shift) ? int(rand(255)) : int(rand(254)) + 1;
return chr( $n );
}

__END__

Update: It looks like there is a 2-way tie between avar and moritz. I
went ahead and wrote an in-place version of moritz's code. Thanks to
SuicideJunkie for fixing my stupidity in the test data. The script now
looks like:

#!/usr/bin/perl

use 5.6.0;

use strict;
use warnings FATAL => 'all';

#use Test::More no_plan => 1;
use Benchmark qw( cmpthese );

my $s1 = do_rand(0, 100_000);
my $s2 = do_rand(1, 100_000);
my $expected = split1( \$s1, \$s2 );

cmpthese( -3, {
'avar2' => sub {
my $s3 = $s1; avar2( \$s3, \$s2 );
# is( $s3, $expected, "avar2" );
},
'moritz' => sub {
my $s3 = $s1; moritz( \$s3, \$s2 );
# is( $s3, $expected, "moritz" );
},
});

sub split1 {
my ($s1, $s2) = @_;

my @s1 = split //, $$s1;
my @s2 = split //, $$s2;

foreach my $idx ( 0 .. $#s1 ) {
if ( $s1[$idx] eq chr(0) ) {
$s1[$idx] = $s2[$idx];
}
}

$$s1 = join '', @s1;
}

sub avar2 {
my ($s1, $s2) = @_;
use bytes;
$$s1 =~ s/\0/substr $$s2, pos($$s1), 1/eg;
}

sub moritz {
my ($s1, $s2) = @_;

my $pos = 0;
while ( 0 < ( $pos = index $$s1, "\000", $pos ) ) {
substr( $$s1, $pos, 1 ) = substr( $$s2, $pos, 1 );
}
}

sub do_rand {
my ($min, $len) = @_;
my $n = "";
for (1 .. $len) {
$n .= chr( rand(255-$min)+$min )
}
return $n;
}

__END__

I'm going to keep it open until 24 hours have passed from the initial
posting of this node. If no-one gets any faster, both moritz and avar
have a meter of beer from me.


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

Abigail

unread,
Sep 13, 2007, 6:56:13 AM9/13/07
to
_
Michele Dondi (bik....@tiscalinet.it) wrote on VCXXVI September MCMXCIII
in <URL:news:nd4ie3t1dv6sq4ae8...@4ax.com>:
:: Just copying here from: <http://perlmonks.org/?node_id=638552>

:: (Please check the thread for other interventions. BTW: I'm *not* the
:: author of the post...)


Is there a point of reposting perlmonks threads to Usenet? People
who are interested in perlmonks already read it. People who don't,
well, they don't and there's no need to repost for them.

Abigail
--
$" = "/"; split // => eval join "+" => 1 .. 7;
*{"@_"} = sub {foreach (sort keys %_) {print "$_ $_{$_} "}};
%_ = (Just => another => Perl => Hacker); &{%_};

Michele Dondi

unread,
Sep 13, 2007, 7:52:05 AM9/13/07
to
On 13 Sep 2007 10:56:13 GMT, Abigail <abi...@abigail.be> wrote:

>:: Just copying here from: <http://perlmonks.org/?node_id=638552>
>:: (Please check the thread for other interventions. BTW: I'm *not* the
>:: author of the post...)
>
>Is there a point of reposting perlmonks threads to Usenet? People
>who are interested in perlmonks already read it. People who don't,
>well, they don't and there's no need to repost for them.

I *do* think that there's a point, for people interested in *Perl* who
may like one interface and dislike the other one. And I think there's
a point reposting stuff from one place to the other if it contributes
to Perl knowledge or is otherwise intriguing. For the future I'll
stick to include a [PM] "tag" in the subject for those like you who
will want to filter such posts out a priori.

Abigail

unread,
Sep 13, 2007, 8:15:10 AM9/13/07
to
_
Michele Dondi (bik....@tiscalinet.it) wrote on VCXXVI September MCMXCIII
in <URL:news:uk8ie310pkglfhd6n...@4ax.com>:
$$ On 13 Sep 2007 10:56:13 GMT, Abigail <abi...@abigail.be> wrote:
$$
$$ >:: Just copying here from: <http://perlmonks.org/?node_id=638552>
$$ >:: (Please check the thread for other interventions. BTW: I'm *not* the
$$ >:: author of the post...)
$$ >
$$ >Is there a point of reposting perlmonks threads to Usenet? People
$$ >who are interested in perlmonks already read it. People who don't,
$$ >well, they don't and there's no need to repost for them.
$$
$$ I *do* think that there's a point, for people interested in *Perl* who
$$ may like one interface and dislike the other one. And I think there's
$$ a point reposting stuff from one place to the other if it contributes
$$ to Perl knowledge or is otherwise intriguing. For the future I'll
$$ stick to include a [PM] "tag" in the subject for those like you who
$$ will want to filter such posts out a priori.


Goodbye.

*PLONK*


Abigail
--
sub f{sprintf'%c%s',$_[0],$_[1]}print f(74,f(117,f(115,f(116,f(32,f(97,
f(110,f(111,f(116,f(104,f(0x65,f(114,f(32,f(80,f(101,f(114,f(0x6c,f(32,
f(0x48,f(97,f(99,f(107,f(101,f(114,f(10,q ff)))))))))))))))))))))))))

Charlton Wilbur

unread,
Sep 13, 2007, 11:39:28 AM9/13/07
to
>>>>> "MD" == Michele Dondi <bik....@tiscalinet.it> writes:

MD> I *do* think that there's a point, for people interested in
MD> *Perl* who may like one interface and dislike the other
MD> one. And I think there's a point reposting stuff from one
MD> place to the other if it contributes to Perl knowledge or is
MD> otherwise intriguing.

I'm afraid I concur with Abigail here. If I wanted to read Perlmonks,
I'd read Perlmonks.

If Perlmonks is lacking in competent and knowledgeable posters, then
perhaps it's time to reexamine their choice of interfaces. And if
they're not so lacking, reposting Perlmonks threads here and clpm
threads there serves only to annoy.

Charlton

--
Charlton Wilbur
cwi...@chromatico.net

Uri Guttman

unread,
Sep 13, 2007, 12:43:21 PM9/13/07
to
>>>>> "MD" == Michele Dondi <bik....@tiscalinet.it> writes:


MD> for my $idx ( 0 .. length($s1) ) {

MD> if ( substr($s1,$idx,1) eq chr(0) ) {

you can loop over the $s1 chars with a regex of /./g which should/could be
faster than a substr call

MD> substr($s1, $idx, 1) = substr($s2, $idx, 1);

use 4 arg substr which is much faster than lvalue substr

MD> Update: It looks like there is a 2-way tie between avar and moritz. I
MD> went ahead and wrote an in-place version of moritz's code. Thanks to
MD> SuicideJunkie for fixing my stupidity in the test data. The script now
MD> looks like:


MD> sub avar2 {
MD> my ($s1, $s2) = @_;
MD> use bytes;
MD> $$s1 =~ s/\0/substr $$s2, pos($$s1), 1/eg;
MD> }

i was thinking along that line before i realized you had gotten answers.

MD> sub moritz {
MD> my ($s1, $s2) = @_;

MD> my $pos = 0;
MD> while ( 0 < ( $pos = index $$s1, "\000", $pos ) ) {
MD> substr( $$s1, $pos, 1 ) = substr( $$s2, $pos, 1 );

again, 4 arg substr will be much faster than lvalue substr.

another crazy idea is to use something like $s1 =~ /(\0)/g to find and
grab all the zero spots. then use @+ (or @- whichever works right) as a
list of indexes to substr out of $s2 and into $s1. that line can be done
in a for modifier. something like this (very untested):

@zeroes = $s1 =~ /(\0)/g ;
substr( $s1, $_, 1, substr( $s2, $_, 1 ) ) for @- ;

one last idea is maybe bit::vector has such a feature or methods to
build one. it is very fast and optimized for this sort of thing.

uri

--
Uri Guttman ------ u...@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org

xho...@gmail.com

unread,
Sep 13, 2007, 1:39:06 PM9/13/07
to
Michele Dondi <bik....@tiscalinet.it> wrote:
>
> Update: It looks like there is a 2-way tie between avar and moritz. I
> went ahead and wrote an in-place version of moritz's code. Thanks to
> SuicideJunkie for fixing my stupidity in the test data. The script now
> looks like:
>
> #!/usr/bin/perl
>
> use 5.6.0;
>
> use strict;
> use warnings FATAL => 'all';
>
> #use Test::More no_plan => 1;
> use Benchmark qw( cmpthese );
>
> my $s1 = do_rand(0, 100_000);
> my $s2 = do_rand(1, 100_000);
> my $expected = split1( \$s1, \$s2 );

Because split1 modifies $s1 in place, $s1 is equal to $expected
even before your tests start. Therefore, a no-op routine would still
satisfy your "is" assertions (were they not commented out). Once I fix
that, moritz seems to start giving the wrong answers.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.

Keith Keller

unread,
Sep 13, 2007, 2:12:42 PM9/13/07
to
On 2007-09-13, Michele Dondi <bik....@tiscalinet.it> wrote:
>
> I'm going to keep it open until 24 hours have passed from the initial
> posting of this node. If no-one gets any faster, both moritz and avar
> have a meter of beer from me.

Beer is measured in volume, not length. The OP (at PM) should really be
offering a cubic meter of beer, and moritz and avar should demand such.

--keith

--
kkeller...@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information

xho...@gmail.com

unread,
Sep 13, 2007, 2:46:55 PM9/13/07
to
xho...@gmail.com wrote:
> Michele Dondi <bik....@tiscalinet.it> wrote:
> >
> > Update: It looks like there is a 2-way tie between avar and moritz. I
> > went ahead and wrote an in-place version of moritz's code. Thanks to
> > SuicideJunkie for fixing my stupidity in the test data. The script now
> > looks like:
> >
> > #!/usr/bin/perl
> >
> > use 5.6.0;
> >
> > use strict;
> > use warnings FATAL => 'all';
> >
> > #use Test::More no_plan => 1;
> > use Benchmark qw( cmpthese );
> >
> > my $s1 = do_rand(0, 100_000);
> > my $s2 = do_rand(1, 100_000);
> > my $expected = split1( \$s1, \$s2 );
>
> Because split1 modifies $s1 in place, $s1 is equal to $expected
> even before your tests start. Therefore, a no-op routine would still
> satisfy your "is" assertions (were they not commented out). Once I fix
> that, moritz seems to start giving the wrong answers.

The problem with moritz is that it compares index(...) to >0, rather than
either >-1 or >=0, for success, so it fails when the first char is \000. I
fixed that, and changed to 4-argument substr.

For my own effort, I perhaps cheated by using Inline C, and depending on
the C representations of both strings being null terminated.

Rate split1 substr1 avar2 moritz moritz2 foo2
split1 5.35/s -- -82% -100% -100% -100% -100%
substr1 30.3/s 467% -- -97% -98% -99% -100%
avar2 1160/s 21595% 3725% -- -39% -44% -86%
moritz 1907/s 35576% 6190% 64% -- -8% -77%
moritz2 2080/s 38806% 6759% 79% 9% -- -75%
foo2 8318/s 155488% 27330% 617% 336% 300% --


use Inline C=> 'DATA';
...
__DATA__
__C__
void foo2 (unsigned char * s1, unsigned char * s2) {
while ( *s2 != NULL ) {
while ( *s1 != NULL ) {
s1++; s2++;
};
*s1=*s2;
};
};

Josef Moellers

unread,
Sep 13, 2007, 3:21:53 PM9/13/07
to
Keith Keller wrote:
> On 2007-09-13, Michele Dondi <bik....@tiscalinet.it> wrote:
>> I'm going to keep it open until 24 hours have passed from the initial
>> posting of this node. If no-one gets any faster, both moritz and avar
>> have a meter of beer from me.
>
> Beer is measured in volume, not length. The OP (at PM) should really be
> offering a cubic meter of beer, and moritz and avar should demand such.

It certainly depends on where you live: "a meter of beer" is quit common
in some areas here in Germany: just place glasses next to each other for
a length of 1 meter! There is even a competition: two drinkers start at
each end and whoever reaches the middle first, wins.

Josef
--
Mails please to josef dot moellers
and I'm on gmx dot de.

Azazel

unread,
Sep 13, 2007, 3:47:54 PM9/13/07
to

And of course there is always the yard of ale:

http://en.wikipedia.org/wiki/Yard_(beer)

Az.

Michele Dondi

unread,
Sep 13, 2007, 5:02:39 PM9/13/07
to
On 13 Sep 2007 11:39:28 -0400, Charlton Wilbur
<cwi...@chromatico.net> wrote:

>If Perlmonks is lacking in competent and knowledgeable posters, then
>perhaps it's time to reexamine their choice of interfaces. And if

Well, of course if I see that many people agree with you and Abigail,
then I will stop doing so. Not that I do it *routinely* nor that I've
done that so many times...

However PM is *not* lacking in competent and knowledgeable posters, in
fact did the OP in this particular example receive quite a lot of
*sensible* answers.

Yet the problem seemed interesting enough to be shared: that it was
posted there is somewhat of circumstance. If I had stumbled in it by
randomly browsing the web and still found it interesting, then I would
have posted it here as well.

>they're not so lacking, reposting Perlmonks threads here and clpm
>threads there serves only to annoy.

Well it may be and may not be. I copied there the content of a thread
posted here some months ago (with proper attributions) and at
<http://perlmonks.org/?node_id=638535> you can read:

: ++ for bringing that here, so I read it :-)
:
: I didn't know about @CARP_NOT, so I learned something new today.

Also, Uri Guttman and xhoster took a shoot at the actual problem, so
they must have found it interesting.

Honestly, I don't want to bother anyone. Do you think that
occasionally posting here interesting stuff from PM with a suitable
tag in the Subject for you and others to easily filter it out would be
so bad?

Charlton Wilbur

unread,
Sep 13, 2007, 6:29:55 PM9/13/07
to
>>>>> "MD" == Michele Dondi <bik....@tiscalinet.it> writes:

MD> Honestly, I don't want to bother anyone. Do you think that
MD> occasionally posting here interesting stuff from PM with a
MD> suitable tag in the Subject for you and others to easily
MD> filter it out would be so bad?

I think that both Usenet and Perlmonks are interactive media, and both
are best served by an occasional post saying something like "there's
an interesting conversation going on about $subject over on
Perlmonks." People who want Perlmonks know where to find it, by and
large, and it's not as if clpm is hurting for traffic.

I don't think "Post it, and if people find it unwelcome they can
filter it out" is a polite strategy to pursue. But I'm not the
arbiter of clpm behavior, except in that I'm fairly quick to score
subjects and posters down.

Uri Guttman

unread,
Sep 13, 2007, 6:40:19 PM9/13/07
to
>>>>> "MD" == Michele Dondi <bik....@tiscalinet.it> writes:

MD> On 13 Sep 2007 11:39:28 -0400, Charlton Wilbur
MD> <cwi...@chromatico.net> wrote:

>> If Perlmonks is lacking in competent and knowledgeable posters, then
>> perhaps it's time to reexamine their choice of interfaces. And if

MD> Well, of course if I see that many people agree with you and Abigail,
MD> then I will stop doing so. Not that I do it *routinely* nor that I've
MD> done that so many times...

i am not there because of the web api (why no news/email gateway?) and
because i have never was into the monk culture. and yes i know plenty of
people there but i have seen too many idiots. there are idiots on usenet
too but emacs makes it easier to ignore them.

Tad McClellan

unread,
Sep 13, 2007, 6:50:46 PM9/13/07
to
Charlton Wilbur <cwi...@chromatico.net> wrote:
>>>>>> "MD" == Michele Dondi <bik....@tiscalinet.it> writes:
>
> MD> I *do* think that there's a point, for people interested in
> MD> *Perl* who may like one interface and dislike the other
> MD> one. And I think there's a point reposting stuff from one
> MD> place to the other if it contributes to Perl knowledge or is
> MD> otherwise intriguing.
>
> I'm afraid I concur with Abigail here.


<aol> Me too! </aol>


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

Bart Lateur

unread,
Sep 13, 2007, 8:43:02 PM9/13/07
to
Keith Keller wrote:

>Beer is measured in volume, not length. The OP (at PM) should really be
>offering a cubic meter of beer, and moritz and avar should demand such.

Funny you should mention that. I just asked about that a few days ago,
to the guy who started it (with the Perl for Windows + free C compiler
challenge):

<http://use.perl.org/comments.pl?sid=36903&cid=57707>

--
Bart.

brian d foy

unread,
Sep 14, 2007, 12:50:49 AM9/14/07
to
In article <ri8je3t355us9d8tb...@4ax.com>, Michele Dondi
<bik....@tiscalinet.it> wrote:

> On 13 Sep 2007 11:39:28 -0400, Charlton Wilbur
> <cwi...@chromatico.net> wrote:
>
> >If Perlmonks is lacking in competent and knowledgeable posters, then
> >perhaps it's time to reexamine their choice of interfaces. And if

> Well, of course if I see that many people agree with you and Abigail,
> then I will stop doing so. Not that I do it *routinely* nor that I've
> done that so many times...

I agree with them. It's a lame thing to do, reposting other people's
stuff (heh, from the guy who runs the perlfaq server :).

Posting your own stuff is fine, or your own thoughts on someone else's
ideas is fine, but just reposting something with no transformative
effect is a pillar of copyright infringement, and it's rude to the
author.

brian d foy

unread,
Sep 14, 2007, 1:01:32 AM9/14/07
to
In article <ri8je3t355us9d8tb...@4ax.com>, Michele Dondi
<bik....@tiscalinet.it> wrote:

> Honestly, I don't want to bother anyone. Do you think that
> occasionally posting here interesting stuff from PM with a suitable
> tag in the Subject for you and others to easily filter it out would be
> so bad?

How about posting original content of which you are the author? Talking
about a problem that you think is interesting, expounding on it, and so
on would be a lot better.

Otherwise, let the original authors decide where to post their own work.

jgr...@ti.com

unread,
Sep 14, 2007, 11:03:04 AM9/14/07
to

Michele Dondi <bik....@tiscalinet.it> writes:

> I have two very long (>64k) strings of equal lengths - $s1 and $s2.
> They are strings of bytes, meaning that any value from chr(0) to
> chr(255) is legal. $s2, however, will not have any chr(0). $s1 may or
> may not have any. What I need to do is look at each byte in $s1 and if
> it is chr(0), replace it with the corresponding byte in $s2.

Benchmark this:

(my $s1m = $s1) =~ tr/\000-\377/\377\000/;
$s1 |= ($s2 & $s1m);

--
Joel

Wade Ward

unread,
Sep 14, 2007, 11:02:56 PM9/14/07
to


"Michele Dondi" <bik....@tiscalinet.it> wrote in message
news:nd4ie3t1dv6sq4ae8...@4ax.com...


> Just copying here from: <http://perlmonks.org/?node_id=638552>
> (Please check the thread for other interventions. BTW: I'm *not* the
> author of the post...)
>

> I'm going to keep it open until 24 hours have passed from the initial


> posting of this node. If no-one gets any faster, both moritz and avar
> have a meter of beer from me.

Point me to the finish line. siehe Anhang
--
Wade Ward
wa...@zaxfuuq.net
'If they took all the "And it came to pass's" out
of the Book of Mormon, it would be a pamphlet.'
--Mark Twain
Hi. This is the qmail-send program at
smtpauth04.prod.mesa1.secureserver.net.
I'm afraid I wasn't able to deliver your message to the following addresses.
This is a permanent error; I've given up. Sorry it didn't work out.

<bik....@tiscalinet.it>:
213.205.33.35 does not like recipient.
Remote host said: 552 RCPT TO:<bik....@tiscalinet.it> Mailbox disk quota
exceeded
Giving up on 213.205.33.35.

--- Below this line is a copy of the message.

Return-Path: <wa...@zaxfuuq.net>
Received: (qmail 7712 invoked from network); 13 Sep 2007 02:25:39 -0000
Received: from unknown (68.35.170.134)
by smtpauth04.prod.mesa1.secureserver.net (64.202.165.95) with ESMTP; 13
Sep 2007 02:25:39 -0000
Message-ID: <001d01c7f5b5$bab665f0$86aa2344@merl>
From: "wade ward" <wa...@zaxfuuq.net>
To: "Michele Dondi" <bik....@tiscalinet.it>
References: <tbafe39pv81keefsj...@4ax.com>
Subject: Re: Commented braces
Date: Wed, 12 Sep 2007 20:25:26 -0700
MIME-Version: 1.0
Content-Type: text/plain;
format=flowed;
charset="iso-8859-1";
reply-type=original
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.3138
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138

Hi Michele,

I just got back online after moving and see that you're still contributing
to clpmisc. I'll be lurking and finding a new reference book. Just saying
hi.
--
Merrill
a.k.a.
Wade Ward
wa...@zaxfuuq.net
'If they took all the "And it came to pass's" out
of the Book of Mormon, it would be a pamphlet.'
--Mark Twain

Hi. This is the qmail-send program at
smtpauth01.prod.mesa1.secureserver.net.
I'm afraid I wasn't able to deliver your message to the following addresses.
This is a permanent error; I've given up. Sorry it didn't work out.

<bla...@jabber.org>:
208.245.212.69 does not like recipient.
Remote host said: 550 5.1.1 <bla...@jabber.org>: Recipient address rejected:
User unknown in local recipient table
Giving up on 208.245.212.69.

--- Below this line is a copy of the message.

Return-Path: <wa...@zaxfuuq.net>
Received: (qmail 8048 invoked from network); 14 Sep 2007 21:05:18 -0000
Received: from unknown (68.35.170.134)
by smtpauth01.prod.mesa1.secureserver.net (64.202.165.181) with ESMTP; 14
Sep 2007 21:05:18 -0000
Message-ID: <004a01c7f71b$4e340c40$86aa2344@merl>
From: "wade ward" <wa...@zaxfuuq.net>
To: <bla...@jabber.org>
Subject: whassup?
Date: Fri, 14 Sep 2007 15:05:04 -0700
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0047_01C7F6E0.A1546B80"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.3138
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138

This is a multi-part message in MIME format.

------=_NextPart_000_0047_01C7F6E0.A1546B80
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

What's up?

I'm ready to take another stab at perl. I had a couple questions, if =
you're game.
--
Merrill
aka Wade Ward
------=_NextPart_000_0047_01C7F6E0.A1546B80
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.5730.11" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>What's up?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I'm ready to take another stab at =
perl.&nbsp; I had=20
a couple questions, if you're game.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>--</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Merrill</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>aka Wade =
Ward</FONT></DIV></BODY></HTML>

------=_NextPart_000_0047_01C7F6E0.A1546B80--


Wade Ward

unread,
Sep 15, 2007, 12:55:34 AM9/15/07
to

"Abigail" <abi...@abigail.be> wrote in message
news:slrnfeiad1...@alexandra.abigail.be...

> Goodbye.
>
> *PLONK*
Tough crowd.

Wade Ward

unread,
Sep 15, 2007, 6:06:28 AM9/15/07
to

"brian d foy" <brian...@gmail.com> wrote in message
news:130920072350495491%brian...@gmail.com...


> In article <ri8je3t355us9d8tb...@4ax.com>, Michele Dondi
> <bik....@tiscalinet.it> wrote:
>
>> On 13 Sep 2007 11:39:28 -0400, Charlton Wilbur
>> <cwi...@chromatico.net> wrote:
>>
>> >If Perlmonks is lacking in competent and knowledgeable posters, then
>> >perhaps it's time to reexamine their choice of interfaces. And if

I can see that there's a political situation with Perlmonks; you must
believe me when I say it doesn't concern me; me, your garden perl-learner in
c.l.p.misc.

>> Well, of course if I see that many people agree with you and Abigail,
>> then I will stop doing so. Not that I do it *routinely* nor that I've
>> done that so many times...
>
> I agree with them. It's a lame thing to do, reposting other people's
> stuff (heh, from the guy who runs the perlfaq server :).
>
> Posting your own stuff is fine, or your own thoughts on someone else's
> ideas is fine, but just reposting something with no transformative
> effect is a pillar of copyright infringement, and it's rude to the
> author.

It serves as scaffolding to persons who are newer to the syntax. As far as
I'm concerned, I solved the posed problem instantaneously, because I never
got the question within this 24-hr. period that ends in the middle of the
day, Italian time.

Wade Ward

unread,
Sep 15, 2007, 6:33:05 AM9/15/07
to


"brian d foy" <brian...@gmail.com> wrote in message

news:140920070001324076%brian...@gmail.com...

http://www.zaxfuuq.net/perl1.htm

Martijn Lievaart

unread,
Sep 15, 2007, 5:48:30 AM9/15/07
to
On Thu, 13 Sep 2007 18:46:55 +0000, xhoster wrote:

> For my own effort, I perhaps cheated by using Inline C, and depending on
> the C representations of both strings being null terminated.

But s1 contains null characters, so this won't work.

M4

Michele Dondi

unread,
Sep 15, 2007, 6:44:46 AM9/15/07
to
On Fri, 14 Sep 2007 21:55:34 -0700, "Wade Ward" <zax...@invalid.net>
wrote:

>> *PLONK*
>Tough crowd.

Funnily enough I have occasionally been "accused" of being one of the
toughest myself.

Wade Ward

unread,
Sep 15, 2007, 8:44:23 AM9/15/07
to

"Michele Dondi" <bik....@tiscalinet.it> wrote in message
news:lrdne3p4gvaq88pa3...@4ax.com...

> On Fri, 14 Sep 2007 21:55:34 -0700, "Wade Ward" <zax...@invalid.net>
> wrote:
>
>>> *PLONK*
>>Tough crowd.
>
> Funnily enough I have occasionally been "accused" of being one of the
> toughest myself.
Did I merit beer up to my knees? If not, I can see whence the criticism
comes.

xho...@gmail.com

unread,
Sep 15, 2007, 7:22:29 PM9/15/07
to

Did you try it?

If s1 did *not* contain null characters, then there would be no point.
The fact that s1 does contain null characters is what this is all about.
The point is that it also needs to end with a null character, regardless
of what null it has in the middle.

Martijn Lievaart

unread,
Sep 16, 2007, 5:23:02 PM9/16/07
to
On Sat, 15 Sep 2007 23:22:29 +0000, xhoster wrote:

> Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
>> On Thu, 13 Sep 2007 18:46:55 +0000, xhoster wrote:
>>
>> > For my own effort, I perhaps cheated by using Inline C, and depending
>> > on the C representations of both strings being null terminated.
>>
>> But s1 contains null characters, so this won't work.
>
> Did you try it?
>
> If s1 did *not* contain null characters, then there would be no point.
> The fact that s1 does contain null characters is what this is all about.
> The point is that it also needs to end with a null character, regardless
> of what null it has in the middle.

No I did not try it. I don't have to. this C implementation stops at the
first null character. Why do you think it'll behave otherwise?

M4

Peter J. Holzer

unread,
Sep 16, 2007, 6:24:29 PM9/16/07
to
On 2007-09-16 21:23, Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
> On Sat, 15 Sep 2007 23:22:29 +0000, xhoster wrote:
>> Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
>>> On Thu, 13 Sep 2007 18:46:55 +0000, xhoster wrote:
>>>
>>> > For my own effort, I perhaps cheated by using Inline C, and depending
>>> > on the C representations of both strings being null terminated.
>>>
>>> But s1 contains null characters, so this won't work.
>>
>> Did you try it?
>>
>> If s1 did *not* contain null characters, then there would be no point.
>> The fact that s1 does contain null characters is what this is all about.
>> The point is that it also needs to end with a null character, regardless
>> of what null it has in the middle.
>
> No I did not try it. I don't have to.

You may not have to try it, but you have to read the code more
carefully.

> this C implementation stops at the first null character. Why do you
> think it'll behave otherwise?

Because that's how he programmed it?

(BTW, the use of NULL is wrong - that should be 0 or '\0').

hp


--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | h...@hjp.at |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"

xho...@gmail.com

unread,
Sep 16, 2007, 7:22:32 PM9/16/07
to
Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
> On Sat, 15 Sep 2007 23:22:29 +0000, xhoster wrote:
>
> > Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
> >> On Thu, 13 Sep 2007 18:46:55 +0000, xhoster wrote:
> >>
> >> > For my own effort, I perhaps cheated by using Inline C, and
> >> > depending on the C representations of both strings being null
> >> > terminated.
> >>
> >> But s1 contains null characters, so this won't work.
> >
> > Did you try it?
> >
> > If s1 did *not* contain null characters, then there would be no point.
> > The fact that s1 does contain null characters is what this is all
> > about. The point is that it also needs to end with a null character,
> > regardless of what null it has in the middle.
>
> No I did not try it.

Or, apparently, understand it.

> I don't have to. this C implementation stops at the
> first null character.

Sure, it stops at the first null in s2. But not the first null in s1.
Well, the *inner* loop does stop at the first null in s1, but then it
restarts. And restarts again. And again. It doesn't stop for good until it
hits the "first" (and last) null in s2.

> Why do you think it'll behave otherwise?

Because I wrote it that way on purpose, and because I tested it.

Michele Dondi

unread,
Sep 17, 2007, 9:52:30 AM9/17/07
to
On 13 Sep 2007 18:29:55 -0400, Charlton Wilbur
<cwi...@chromatico.net> wrote:

>I think that both Usenet and Perlmonks are interactive media, and both
>are best served by an occasional post saying something like "there's
>an interesting conversation going on about $subject over on
>Perlmonks." People who want Perlmonks know where to find it, by and

Good point. I still beg to differ in that experimental evidence shows
that when giving just a link people tend not to answer: perhaps simply
warnock applies, but generally there's not evidence of posting in the
other media even anonymously either. Instead in this very thread you
can see that some people *did* answer taking advantage of their own
newsreaders' facilities. Some times even knowledgeable and smart
people must be "brought by hand".

Anyway those above are just a few random observations from me and I
won't take them as an excuse to keep doing so: it was my intent to
provide a *service* to the community, albeit admittedly a "minor" one.
But if it's not received as such, if it's annoying instead, then I'm
in no way investing my time and resources in such an activity?

>large, and it's not as if clpm is hurting for traffic.

What do you mean? Too much traffic or too little? Personally I'm now
ignoring most threads. I got tired of posts about how to "split a
line" or validate some params for webby stuff... There's very little
*interesting* traffic. But maybe that's just me.

>I don't think "Post it, and if people find it unwelcome they can
>filter it out" is a polite strategy to pursue. But I'm not the

I hope you will agree that it was an attempt at politeness. But as I
wrote, I'm not insisting anyway.

Michele Dondi

unread,
Sep 17, 2007, 9:53:50 AM9/17/07
to
On Thu, 13 Sep 2007 22:40:19 GMT, Uri Guttman <u...@stemsystems.com>
wrote:

>i am not there because of the web api (why no news/email gateway?) and

^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^

>because i have never was into the monk culture. and yes i know plenty of

I would dream of such a beast.

Michele Dondi

unread,
Sep 17, 2007, 9:59:46 AM9/17/07
to
On Thu, 13 Sep 2007 23:50:49 -0500, brian d foy
<brian...@gmail.com> wrote:

>> Well, of course if I see that many people agree with you and Abigail,
>> then I will stop doing so. Not that I do it *routinely* nor that I've
>> done that so many times...
>
>I agree with them. It's a lame thing to do, reposting other people's
>stuff (heh, from the guy who runs the perlfaq server :).
>
>Posting your own stuff is fine, or your own thoughts on someone else's
>ideas is fine, but just reposting something with no transformative
>effect is a pillar of copyright infringement, and it's rude to the
>author.

As I wrote in reply to Charlton, I'm stopping anyway, but I can't see
how so: are texts posted to public fora and newsgroups supposed to
count as copyrighted material? Do you see a problem of ethic nature?
(Especially taking into account the inclusion of proper attributions
and/*or* a link to the original post?)

Incidentally, a rewriting of an entire thread, summing up the
interesting bits in an organized manner and the rougher practice of
bare copying -but possibly for some formatting- are commonly separated
simply by a thing called *lack of time*.

Michele Dondi

unread,
Sep 17, 2007, 10:01:50 AM9/17/07
to
On Sat, 15 Sep 2007 03:06:28 -0700, "Wade Ward" <zax...@invalid.net>
wrote:

>It serves as scaffolding to persons who are newer to the syntax. As far as

>I'm concerned, I solved the posed problem instantaneously, because I never
>got the question within this 24-hr. period that ends in the middle of the
>day, Italian time.

Of course the question was practical in nature, and the 24 hours limit
applied to that side of it. Though it was and still is interesting as
of itself. All this, of course, rigorously IMHO.

Abigail

unread,
Sep 17, 2007, 10:05:53 AM9/17/07
to
_
Uri Guttman (u...@stemsystems.com) wrote on VCXXVI September MCMXCIII in
<URL:news:x7abrqj...@mail.sysarch.com>:
// >>>>> "MD" == Michele Dondi <bik....@tiscalinet.it> writes:
//
// MD> On 13 Sep 2007 11:39:28 -0400, Charlton Wilbur
// MD> <cwi...@chromatico.net> wrote:
//
// >> If Perlmonks is lacking in competent and knowledgeable posters, then
// >> perhaps it's time to reexamine their choice of interfaces. And if
//
// MD> Well, of course if I see that many people agree with you and Abigail,
// MD> then I will stop doing so. Not that I do it *routinely* nor that I've
// MD> done that so many times...
//
// i am not there because of the web api (why no news/email gateway?) and

A news/email gateway would give you the worst of two worlds, wouldn't it?
You'll get messages on usenet that don't quote context, and you'll get
webpages that contain the same text over and over again.

// because i have never was into the monk culture. and yes i know plenty of
// people there but i have seen too many idiots. there are idiots on usenet
// too but emacs makes it easier to ignore them.


Not to mention that on Perlmonks they don't care at all whether your
answer is correct or not. As long as you pat each other on the back,
telling how wonderful all the monks are, all is fine.

I rather not have the Perlmonk culture infiltrating on Usenet.


Abigail
--
END {print "Hacker\n"}
BEGIN {print "Just " }
CHECK {print "another "}
INIT {print "Perl " }

Michele Dondi

unread,
Sep 17, 2007, 10:11:31 AM9/17/07
to
On Fri, 14 Sep 2007 00:01:32 -0500, brian d foy
<brian...@gmail.com> wrote:

>How about posting original content of which you are the author? Talking

Sometimes I do. Didn't I?

>about a problem that you think is interesting, expounding on it, and so
>on would be a lot better.

Of course. Just as obviously I'm not that smart. And while *creating*
knowledge is a vastly superior activity, *spreading* it shouldn't be
that bad either.

>Otherwise, let the original authors decide where to post their own work.

Original authors often post just to one place out of habit and
convenience. Some readers just stick to reading in one place out of
habit and convenience. Some of the latter ones will miss forever some
interesting bits from some of the former ones sometime. I was trying
to contribute a tiny piece of help to remedy this situation; I was
probably wrong in my judgement, and I will refrain from doing so,
especially in one direction that is.

Michele Dondi

unread,
Sep 17, 2007, 10:20:10 AM9/17/07
to
On Thu, 13 Sep 2007 16:43:21 GMT, Uri Guttman <u...@stemsystems.com>
wrote:

>another crazy idea is to use something like $s1 =~ /(\0)/g to find and
>grab all the zero spots. then use @+ (or @- whichever works right) as a

That is what avar did.

http://perlmonks.org/?node_id=638563

>list of indexes to substr out of $s2 and into $s1. that line can be done
>in a for modifier. something like this (very untested):
>
> @zeroes = $s1 =~ /(\0)/g ;
> substr( $s1, $_, 1, substr( $s2, $_, 1 ) ) for @- ;

He did that in a /e:

sub subst
{
my ($s1, $s2) = @_;

my $s3 = $s1;

{
use bytes;
$s3 =~ s/(\0)/substr $s2, $+[0]-1, 1/eg;
}

$s3;
}

>one last idea is maybe bit::vector has such a feature or methods to
>build one. it is very fast and optimized for this sort of thing.

Somebody else suggested that. (I'm not really sure whether before or
after you.) But no actual code was provided or tested.

Michele Dondi

unread,
Sep 17, 2007, 10:24:27 AM9/17/07
to
On 13 Sep 2007 18:46:55 GMT, xho...@gmail.com wrote:

>The problem with moritz is that it compares index(...) to >0, rather than
>either >-1 or >=0, for success, so it fails when the first char is \000. I
>fixed that, and changed to 4-argument substr.

You're right, but the error with the index was already corrected in an
update.

>For my own effort, I perhaps cheated by using Inline C, and depending on
>the C representations of both strings being null terminated.

There's another pair of C solutions:

http://perlmonks.org/?node_id=638724

(I'm not sure but I suppose that depending on the C representations of
both strings being null terminated is not appropriate *for this
particular problem*.)

Charlton Wilbur

unread,
Sep 17, 2007, 10:21:18 AM9/17/07
to
>>>>> "MD" == Michele Dondi <bik....@tiscalinet.it> writes:

>> large, and it's not as if clpm is hurting for traffic.

MD> What do you mean? Too much traffic or too little? Personally
MD> I'm now ignoring most threads. I got tired of posts about how
MD> to "split a line" or validate some params for webby
MD> stuff... There's very little *interesting* traffic. But maybe
MD> that's just me.

I mean that clpm already has a great deal of traffic.

Much of it is admittely not interesting, but knowing that there's a
moderately to very interesting conversation going on in a place where
the interface sets my teeth on edge does not improve matters, and
neither does having selected posts from that conversation relayed here.

>> I don't think "Post it, and if people find it unwelcome they
>> can filter it out" is a polite strategy to pursue.

MD> I hope you will agree that it was an attempt at
MD> politeness. But as I wrote, I'm not insisting anyway.

No, I think you were attempting to improve the signal-to-noise ratio
of clpm, and that's to be commended. I just don't think you actually
succeded, because relaying signal from another place doesn't really help.

Charlton


--
Charlton Wilbur
cwi...@chromatico.net

Michele Dondi

unread,
Sep 17, 2007, 10:29:54 AM9/17/07
to
On Fri, 14 Sep 2007 20:02:56 -0700, "Wade Ward" <zax...@invalid.net>
wrote:

>Wade Ward


>wa...@zaxfuuq.net
>'If they took all the "And it came to pass's" out
>of the Book of Mormon, it would be a pamphlet.'
>--Mark Twain
>Hi. This is the qmail-send program at
>smtpauth04.prod.mesa1.secureserver.net.
>I'm afraid I wasn't able to deliver your message to the following addresses.
>This is a permanent error; I've given up. Sorry it didn't work out.
>
><bik....@tiscalinet.it>:
>213.205.33.35 does not like recipient.
>Remote host said: 552 RCPT TO:<bik....@tiscalinet.it> Mailbox disk quota
>exceeded

I gave you my *real* email address and my jabber contact in another
post. I'm writing to you in point of "test".

Michele Dondi

unread,
Sep 17, 2007, 11:01:03 AM9/17/07
to
On 17 Sep 2007 14:05:53 GMT, Abigail <abi...@abigail.be> wrote:

>// i am not there because of the web api (why no news/email gateway?) and
>
>A news/email gateway would give you the worst of two worlds, wouldn't it?
>You'll get messages on usenet that don't quote context, and you'll get
>webpages that contain the same text over and over again.

I *think* that it could be feasible, abeit hard, to automatically go a
long way in the direction of correcting this. Nothing 100% bulletproof
of course, and still requiring author's interventions. It would be
different if there were a (even more) restricted set of tags for the
web interface and a standard two way translation to pure text media.

>// because i have never was into the monk culture. and yes i know plenty of
>// people there but i have seen too many idiots. there are idiots on usenet
>// too but emacs makes it easier to ignore them.
>
>
>Not to mention that on Perlmonks they don't care at all whether your
>answer is correct or not. As long as you pat each other on the back,
>telling how wonderful all the monks are, all is fine.
>
>I rather not have the Perlmonk culture infiltrating on Usenet.

I don't share *entirely* Abigail's view, but I admit there's some
truth in it.

Michele Dondi

unread,
Sep 17, 2007, 11:02:44 AM9/17/07
to
On Mon, 17 Sep 2007 16:24:27 +0200, Michele Dondi
<bik....@tiscalinet.it> wrote:

>(I'm not sure but I suppose that depending on the C representations of
>both strings being null terminated is not appropriate *for this
>particular problem*.)

Please ignore this. I see it was addressed in another part of this
thread.

Uri Guttman

unread,
Sep 17, 2007, 11:03:51 AM9/17/07
to
>>>>> "A" == Abigail <abi...@abigail.be> writes:

A> _
A> Uri Guttman (u...@stemsystems.com) wrote on VCXXVI September MCMXCIII in
A> <URL:news:x7abrqj...@mail.sysarch.com>:


A> // because i have never was into the monk culture. and yes i know plenty of
A> // people there but i have seen too many idiots. there are idiots
A> on usenet
A> // too but emacs makes it easier to ignore them.

A> Not to mention that on Perlmonks they don't care at all whether your
A> answer is correct or not. As long as you pat each other on the back,
A> telling how wonderful all the monks are, all is fine.

A> I rather not have the Perlmonk culture infiltrating on Usenet.

you expressed my dislike of their culture perfectly. they are more
cliquish that i want to deal with. when i did post some there a while
back, monks who know from nothing ragged my comments. i don't need to
fight twits who don't understand what i am saying. i don't want nor need
to climb a social (not technical) ranking system. that and the web
interface makes it a no brainer for me to ignore the monks.

uri

--
Uri Guttman ------ u...@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org

brian d foy

unread,
Sep 17, 2007, 11:46:33 AM9/17/07
to
In article <9o1te3tk0ak0bgi00...@4ax.com>, Michele Dondi
<bik....@tiscalinet.it> wrote:


> As I wrote in reply to Charlton, I'm stopping anyway, but I can't see
> how so: are texts posted to public fora and newsgroups supposed to
> count as copyrighted material?

Well, depending on the source country and local laws, yes, authorship
is generally automatically counted as copyrighted material just by the
act of creation. The author publishes it in a certain way, such as on
Perlmonks. That doesn't necessarily mean he wants it published in some
other way.

See "transformative effect" discussions about copyright, which I
mentioned earlier.

> Do you see a problem of ethic nature?

Well, I do, but that doesn't mean that everyone does. I certainly think
it is rude to the author to simply repost an entire post.

> (Especially taking into account the inclusion of proper attributions
> and/*or* a link to the original post?)

I don't think you gave proper attribution. You linked to the original
post, but you did not identify the original author in the clpm message.

Michele Dondi

unread,
Sep 17, 2007, 12:35:25 PM9/17/07
to
On Mon, 17 Sep 2007 11:46:33 -0400, brian d foy
<brian...@gmail.com> wrote:

>> (Especially taking into account the inclusion of proper attributions
>> and/*or* a link to the original post?)
>
>I don't think you gave proper attribution. You linked to the original
>post, but you did not identify the original author in the clpm message.

Well, re this particular point I was about to answer you in the
use.perl journal, and I will probably do anyway. You're of course
right and it would be poinltless to claim that I did. (BTW: did you
notice how I emphasized "or" above?) Still I hope you will agree that

1. in all the other posts "of the same nature" I did include the name
or the nick of the original author;

2. even in this particular one I specified that I'm not the author of
the original post, and giving the link also gives one the means to
check who the latter actually is.

Martijn Lievaart

unread,
Sep 17, 2007, 4:08:15 PM9/17/07
to
On Sun, 16 Sep 2007 23:22:32 +0000, xhoster wrote:

>> Why do you think it'll behave otherwise?
>
> Because I wrote it that way on purpose, and because I tested it.

I apologize, you are right.

M4

jgr...@ti.com

unread,
Sep 17, 2007, 3:46:21 PM9/17/07
to
jgr...@ti.com writes:

> Michele Dondi <bik....@tiscalinet.it> writes:
>
> > I have two very long (>64k) strings of equal lengths - $s1 and $s2.
> > They are strings of bytes, meaning that any value from chr(0) to
> > chr(255) is legal. $s2, however, will not have any chr(0). $s1 may or
> > may not have any. What I need to do is look at each byte in $s1 and if
> > it is chr(0), replace it with the corresponding byte in $s2.
>
> (my $s1m = $s1) =~ tr/\000-\377/\377\000/;
> $s1 |= ($s2 & $s1m);

Converted to a subroutine suitable for previous benchmark program

sub trandor_ref{
my ($s1ref, $s2ref) = @_;
(my $s1m = $$s1ref) =~ tr/\000-\377/\377\000/;
$$s1ref |= ($$s2 & $s1m);
}


Benchmark results:
Rate avar2 moritz trandor_ref
avar2 1244/s -- -26% -95%
moritz 1673/s 34% -- -93%
trandor_ref 22904/s 1741% 1269% --

Another example of Perl writing better C than I do.

If perl6 had another version of tr/// that returned the resulting
string instead of the number of matches, this could be a 1-liner.

--
Joel

Tad McClellan

unread,
Sep 17, 2007, 9:57:03 PM9/17/07
to
brian d foy <brian...@gmail.com> wrote:
> In article <9o1te3tk0ak0bgi00...@4ax.com>, Michele Dondi
><bik....@tiscalinet.it> wrote:

> That doesn't necessarily mean he wants it published in some
> other way.
>
> See "transformative effect" discussions about copyright, which I
> mentioned earlier.
>
>> Do you see a problem of ethic nature?
>
> Well, I do, but that doesn't mean that everyone does. I certainly think
> it is rude to the author to simply repost an entire post.


I become incensed with so-called "forums" such as thescripts.com
where my posts here are disguised as if they were posts made there
(by virtue of them labelling me a "Guest", I am NOT their guest,
never was, never will be).

I make killfile entries for the entire domain whenever I come across
such abusers of our community.


Should you happen to "cross pollinate" someone who strongly
opposes the forum they did not post to, it might lead to similar bad
feelings...


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

Tad McClellan

unread,
Sep 17, 2007, 9:42:59 PM9/17/07
to
Michele Dondi <bik....@tiscalinet.it> wrote:
> On Thu, 13 Sep 2007 22:40:19 GMT, Uri Guttman <u...@stemsystems.com>
> wrote:
>
>>i am not there because of the web api (why no news/email gateway?) and
> ^^^^^^^^^^^^^^^^^^
> ^^^^^^^^^^^^^^^^^^
>
>>because i have never was into the monk culture. and yes i know plenty of
>
> I would dream of such a beast.


Your dream is my nightmare. :-(

xho...@gmail.com

unread,
Sep 18, 2007, 12:31:35 AM9/18/07
to
jgr...@ti.com wrote:
> jgr...@ti.com writes:
>
> > Michele Dondi <bik....@tiscalinet.it> writes:
> >
> > > I have two very long (>64k) strings of equal lengths - $s1 and $s2.
> > > They are strings of bytes, meaning that any value from chr(0) to
> > > chr(255) is legal. $s2, however, will not have any chr(0). $s1 may or
> > > may not have any. What I need to do is look at each byte in $s1 and
> > > if it is chr(0), replace it with the corresponding byte in $s2.
> >
> > (my $s1m = $s1) =~ tr/\000-\377/\377\000/;
> > $s1 |= ($s2 & $s1m);
>
> Converted to a subroutine suitable for previous benchmark program
>
> sub trandor_ref{
> my ($s1ref, $s2ref) = @_;
> (my $s1m = $$s1ref) =~ tr/\000-\377/\377\000/;
> $$s1ref |= ($$s2 & $s1m);
> }

Alas, I suspect it is giving you the wrong answer. $s2 is not
declared in that sub, so either you are using the package variable, or are
accidentally using an $s2 declared elsewhere.


>
> Benchmark results:
> Rate avar2 moritz trandor_ref
> avar2 1244/s -- -26% -95%
> moritz 1673/s 34% -- -93%
> trandor_ref 22904/s 1741% 1269% --


When I fix the $$s2 to $$s2ref, it gets a lot slower, but does
give the right answer. If I change the tr to be tr/\000/\377/
it still seems to give the right answer, but is now a lot faster
(The fastest pure Perl implementation I've seen yet.)

avar2 1378/s
trandor_ref 1884/s
moritz 1889/s
joel 2765/s
inline_c 8266/s

Michele Dondi

unread,
Sep 18, 2007, 5:11:54 AM9/18/07
to
On 17 Sep 2007 14:46:21 -0500, jgr...@ti.com wrote:

>If perl6 had another version of tr/// that returned the resulting
>string instead of the number of matches, this could be a 1-liner.

It will certainly have the trans() method to that effect.

Mirco Wahab

unread,
Sep 18, 2007, 11:47:14 AM9/18/07
to
Michele Dondi wrote:
> I have two very long (>64k) strings of equal lengths - $s1 and $s2.
> They are strings of bytes, meaning that any value from chr(0) to
> chr(255) is legal. $s2, however, will not have any chr(0). $s1 may or
> may not have any. What I need to do is look at each byte in $s1 and if
> it is chr(0), replace it with the corresponding byte in $s2. So,
> something like the following code:

I looked over the entries, there are some
XS and some inline, but the obvious one
didn't show up. So I created *it*.

I started with the msvc/win32 thingy (works
perfectly for Activeperl w/MSVC installed)
but will eventually produce the gcc/as/unix
variant.

The gnu style seems to be (for me) somehow
complicated (the intel syntax isn't). So
thats the first part. You can't have it
much faster:

(simple test case added)==>


use Inline C => qq{
// ==>
void wahab_msvc(SV* s, SV* d)
{
STRLEN srclen, dstlen;
char *src = SvPV(SvRV(s), srclen), *dst = SvPV(SvRV(d), dstlen);
if( srclen < dstlen ) croak("block length mismatch!");
_asm mov edi, dst
_asm mov esi, src
_asm mov ecx, dstlen
_asm xor eax, eax
start:
_asm repne scasb
_asm jne done
_asm mov edx, dstlen
_asm sub edx, ecx
_asm mov ah, byte ptr [-1+esi+edx]
_asm mov byte ptr [-1+edi], ah
_asm jmp start
done: ;
}
// <==
};

my $s1 = 'abcdefghijklmn';
my $s2 = 'abcdefghijklmn';

substr($s2,5,1) = "\x0";

wahab_msvc(\$s1, \$s2);

print "\n$s1\n$s2\n";
<==

Any help (gnu style) much appreciated!

M.

Mirco Wahab

unread,
Sep 18, 2007, 5:11:59 PM9/18/07
to
Mirco Wahab wrote:
> ... but will eventually produce the gcc/as/unix variant.

OK, I figured out this part too, so (FWIW) I'll
post it. How's that appliable to the PerlMonks
contest? I don't really know (maybe somebody has a hint).

[start here]

...

use Inline C => qq{

// ==> inline
void by_asm(SV* no_zeros, SV* has_zeros)
{
STRLEN srclen, dstlen;
char *src = SvPV(SvRV(no_zeros), srclen);
char *dst = SvPV(SvRV(has_zeros), dstlen);


if( srclen < dstlen ) croak("block length mismatch!");

#ifdef _MSC_VER


_asm mov edi, dst
_asm mov esi, src
_asm mov ecx, dstlen
_asm xor eax, eax

_asm cld


start:
_asm repne scasb
_asm jne done
_asm mov edx, dstlen
_asm sub edx, ecx
_asm mov ah, byte ptr [-1+esi+edx]
_asm mov byte ptr [-1+edi], ah
_asm jmp start
done: ;

#else
__asm__ __volatile__(
"xorl %%eax, %%eax \\n\\t"
"cld \\n\\t"
"start: \\n\\t"
"repne \\n\\t"
"scasb \\n\\t"
"jne done \\n\\t"
"movl %[l], %%edx \\n\\t"
"subl %%ecx, %%edx \\n\\t"
"movb -1(%%esi,%%edx), %%ah \\n\\t"
"movb %%ah, -1(%%edi) \\n\\t"
"jmp start \\n\\t"
"done: \\n\\t"
: /* no output reg */
: "S"(src),"D"(dst),"c"(dstlen),[l]"m"(dstlen)
);
#endif
}
// <== inline
};

my $s_no_zeros = 'abcdefghijklmnopqrstuvwxyz';

my $s_has_zeros = 'abcdefghijklmnopqrstuvwxyz';
substr($s_has_zeros, 5, 1) = "\x0";
substr($s_has_zeros, -1, 1) = "\x0";

by_asm(\$s_no_zeros, \$s_has_zeros);

print "$s_no_zeros\n$s_has_zeros\n";

[end here]


Regards

M.

Michele Dondi

unread,
Sep 18, 2007, 6:26:43 PM9/18/07
to
On Tue, 18 Sep 2007 23:11:59 +0200, Mirco Wahab
<wa...@chemie.uni-halle.de> wrote:

>OK, I figured out this part too, so (FWIW) I'll
>post it. How's that appliable to the PerlMonks
>contest? I don't really know (maybe somebody has a hint).

If you don't mind (see the discussion at another part of this thread)
I can report your solution there. Even though the "contest" is now
closed, it would be good (IMHO) for completeness. Or else you can do
so yourself, even as an anonymous poster if you like.

Mirco Wahab

unread,
Sep 19, 2007, 3:53:16 AM9/19/07
to
Michele Dondi wrote:
> On Tue, 18 Sep 2007 23:11:59 +0200, Mirco Wahab
> <wa...@chemie.uni-halle.de> wrote:
>
>> OK, I figured out this part too, so (FWIW) I'll
>> post it. How's that appliable to the PerlMonks
>> contest? I don't really know (maybe somebody has a hint).
>
> If you don't mind (see the discussion at another part of this thread)
> I can report your solution there. Even though the "contest" is now
> closed, it would be good (IMHO) for completeness. Or else you can do
> so yourself, even as an anonymous poster if you like.

OK, I did (http://perlmonks.org/?node_id=639826) and
btw. found the vec() solutions to be very very fast
on the Core2 platform. Very interesting.

Thanks & regards

Mirco

Michele Dondi

unread,
Sep 19, 2007, 5:27:10 AM9/19/07
to
On Wed, 19 Sep 2007 09:53:16 +0200, Mirco Wahab
<wa...@chemie.uni-halle.de> wrote:

>> If you don't mind (see the discussion at another part of this thread)
>> I can report your solution there. Even though the "contest" is now
>> closed, it would be good (IMHO) for completeness. Or else you can do
>> so yourself, even as an anonymous poster if you like.
>
>OK, I did (http://perlmonks.org/?node_id=639826) and
>btw. found the vec() solutions to be very very fast
>on the Core2 platform. Very interesting.

++'d! You also posted at the right point IMHO, even if perhaps in
reply to the most complete benchmark at
<http://perlmonks.org/?node_id=638584> would have been more
appropriate. And you may have included the longer portions of code in
readmore tags, just highlighting your contributed code. Anyway, well
done!

>Thanks & regards

Thank you for showing me that my attempt was not completely pointless
notwithstanding the negative reactions.

Wade Ward

unread,
Sep 19, 2007, 7:03:27 AM9/19/07
to

"Tad McClellan" <ta...@seesig.invalid> wrote in message
news:slrnfeub93...@tadmc30.sbcglobal.net...

Tad,

why didn't this work. i think the answer is close to the answer that you
have quoted. siehe anhang.

gruss,
--
Wade Ward
wa...@zaxfuuq.net
"Any dream will do."
you sexy bitch
http://www.zaxfuuq.net/maria1.htm

show this to Brian.
Tell him that mother superior is pissed.

Ask him whether he knows why.
--

Wade Ward
wa...@zaxfuuq.net
"I ain't got time to bleed."
----- Original Message -----
From: bluew...@comcast.net
To: Merrill Jensen
Sent: Tuesday, September 18, 2007 2:02 PM
Subject: Re: thanks


Merrill!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

woooooooooooooooooooohoooooooooooooooooooo! How's NM? All settled in??
What exactly are you doing down there?? What is your new email addy?

Missing you dear. All is well up here. The weather finally turned warm
again. Kids are good, i'm good, joel's good too. We're trying to get used to
the routine of kids being back in school.. Busy as always. Do you have a
phone number yet??

Fill me in!

xoxo
blue

-------------- Original message --------------
From: "Merrill Jensen" <mpje...@comcast.net>

Blue?
--
----- Original Message -----
From: bluew...@comcast.net
To: chicken
Sent: Monday, September 17, 2007 7:10 AM
Subject: FW: thanks


-------------- Forwarded Message: --------------
From: robyn bryan <robyn...@sbcglobal.net>
To: amber fontana <dragonf...@yahoo.com>, amy
<eric...@hotmail.com>, amy erics peterson <ericsw...@gmail.com>,
Angela Guthrie <gizgu...@hotmail.com>, arthur <waitin...@hotmail.com>,
aughra badnewsblonde <jlb...@gmail.com>, belva mccoy <mrsm...@aol.com>,
Bess <be...@bryanfamily.info>, brent tucker <turntab...@yahoo.com>, cathy
<hotts...@hotmail.com>, DAD <rags...@sbcglobal.net>, EMILY ADDICT <ad
di...@myaddictions.com>, gloria <gsmi...@sbcglobal.net>, go green
<neil....@themenofvalor.com>, heather dickerson <hdjul...@yahoo.com>,
jbird <jasonp...@sbcglobal.net>, jeanne bryan <jea...@bryanfamily.info>,
Josanna Gaither <poi...@aol.com>, Karen Reynolds <
;wien2...@alumni.oc.edu>, "katie G." <katie....@gmail.com>, Keda
<mam...@gmail.com>, Kimberly Ann Dominguez <kimberi...@yahoo.com>,
Mandi <maec...@msn.com>, MAryANn <cherr...@sbcglobal.net>, Mendie
<mend...@hotmail.com>, Mendie Schmidt <mendie....@cityofdenton.com>,
misty <bluew...@comcast.net>, Misty Blue <bluew...@sbcglobal.net>, mom
<justj...@sbcglobal.net>, nancy gaither <gai...@tarleton.edu>, Patricia
Santiago <momm...@gmail.com>, rachael pilarcik <skyebu...@aol.com>,
rachel Firefly <firefl...@hotmail.com>, Rilah Ter <ril...@hotmail.com>,
rob bi Tucker <robbi_...@hotmail.com>, robert patel
<sama...@hotmail.com>, Roman <roms...@sbcglobal.net>, rory guthrie
<rors...@sbcglobal.net>, Sarah miller <belleof...@gmail.com>, Scott
Kall <osb...@bresnan.net>, Stan McCoy <stanm...@hotmail.com>, Tiph <
;estoni...@yahoo.com>
Subject: thanks
Date: Mon, 17 Sep 2007 02:49:34 +0000

Thanks a lot!!
Thank you to all those who have kept us safe by sending wonderful
warning bull-etins......and nothing bad will happen in the next 5 minutes,
no 10, no...in the next hour....enjoy. These did make me laugh, I hope you
laugh some too....

I must send my thanks to whoever sent me the one about poop in the
glue on envelopes because I now have to use a wet towel with every envelope
that needs sealing.

Also, now I have to scrub the top of every can I open for the same
reason.

I no longer have any savings because I gave it to a sick girl (Penny
Brown) who is about to die in the hospital for the 1,387,258th time.

I no longer have any money at all, but that will change once I
receive the $15,000 that Bill Gates/Microsoft and AOL are sending me for
participating in their special e-mail program.

I no longer worry about my soul because I have 363,214 angels
looking out for me, and St. Theresa's novena has granted my every wis h.

I no longer eat KFC because their chickens are actually horrible
mutant freaks with no eyes or feathers.

I no longer use cancer-causing deodorants even though I smell like a
water buffalo on a hot day

Thanks to you, I have learned that my prayers only get answered if I
forward an email to seven of my friends and make a wish within five minutes.

Because of your concern I no longer drink Coca Cola because it can
remove toilet stains.

I no longer can buy gasoline without taking someone along to watch
the car so a serial killer won't crawl in my back seat when I'm pumping gas.

I no longer drink Pepsi or Dr. Pepper since the people who make
these products are atheists who refuse to put "Under God" on their cans.

I no longer use Saran wrap in the microwave because it causes
cancer.

And thanks for letting me know I can't boil a cup of water in the
microwave anymore because it will blow up in my face...disfiguring me for
life.
< BR>I no longer check the coin return on pay phones because I could
be pricked with a needle infected with AIDS.

I no longer go to shopping malls because someone will drug me with a
perfume sample and rob me.

I no longer receive packages from UPS or FedEx since they are
actually Al Qaeda in disguise.

I no longer shop at Target since they are French and don't support
our American troops or the Salvation Army.

I no longer answer the phone because someone will ask me to dial a
number for which I will get a phone bill with calls to Jamaica, Uganda,
Singapore, and Uzbekistan

I no longer buy expensive cookies from Neiman Marcus since I now
have their recipe.

Thanks to you, I can't use anyone's toilet but mine because a big
brown African spider is lurking under the seat to cause me instant death
when it bites my butt.

And thanks to your great advice, I can't ever pick up $5.00 dropped
in the parking lot because it probably was placed there b y a sex molester
waiting underneath my car to grab my leg.

I can no longer drive my car because I can't buy gas from certain
gas companies!

If you don't send this e-mail to at least 144,000 people in the next
70 minutes, a large dove with diarrhea will land on your head at 5:00 PM
tomorrow afternoon and the fleas from 12 camels will infest your back,
causing you to grow a hairy hump. I know this will occur because it actually
happened to a friend of my next door neighbor's ex-mother-in-law's second
husband's cousin's beautician...
Have a wonderful day....

Oh, by the way.....

A South American scientist from Argentina, after a lengthy study,
has discovered that people with insufficient brain activity read their
e-mail with their hand on the mouse.

Don't bother taking it off now, it's too late.

gotcha!!!


Mirco Wahab

unread,
Sep 19, 2007, 2:18:27 PM9/19/07
to
Michele Dondi wrote:
> <http://perlmonks.org/?node_id=638584> would have been more
> appropriate. And you may have included the longer portions of code in
> readmore tags, just highlighting your contributed code. Anyway, well

Thanks for your hints, I posted another response
and included links to the code which I deposited
on a server. But I think thats really to late in
this case.

BTW, what I learned (and what I'm glad to know)
is how dead slow the Core2 on CISC IA32 repeated
(prefixed) string operations is (like "rep stringop").

On every Athlon out there, such problems (as said)
can be solved by (IA32) "repne scasb" on the string
in qestion - this will be faster than anything by
a margin.

Not on a Core2, the "rep stringop" will be about
3x slower than a naive load/compare/load/store
sequence.

OK, thats not really Perl related anymore ...

Regards

M.

Wade Ward

unread,
Sep 21, 2007, 4:25:48 AM9/21/07
to

"Tad McClellan" <ta...@seesig.invalid> wrote in message

news:slrnfeuc3f...@tadmc30.sbcglobal.net...


> brian d foy <brian...@gmail.com> wrote:
>> In article <9o1te3tk0ak0bgi00...@4ax.com>, Michele Dondi
>><bik....@tiscalinet.it> wrote:
>
>> That doesn't necessarily mean he wants it published in some
>> other way.
>>
>> See "transformative effect" discussions about copyright, which I
>> mentioned earlier.
>>
>>> Do you see a problem of ethic nature?
>>
>> Well, I do, but that doesn't mean that everyone does. I certainly think
>> it is rude to the author to simply repost an entire post.

Well, I defined some notation as far as that goes.

German-language science forums are, well, better than ours. They are the
*real* well of usenet with a lot of other Europaens and the odd Americans
who can go through an entire party with 29 beers in the fridge, and end up
with survivors. Schrug.

Maybe the river scared them off.

When I did not get the attention to my primary thesis that I was looking
for, I "reposted." The unusual usage was the first person: ich reposte.
Add it to duden.

> Should you happen to "cross pollinate" someone who strongly
> opposes the forum they did not post to, it might lead to similar bad
> feelings...

Are you suggesting that Michele fuck someone? I volunteer, no, I insist, on
absence.

0 new messages