[29602] in Perl-Users-Digest
Perl-Users Digest, Issue: 846 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 13 14:09:43 2007
Date: Thu, 13 Sep 2007 11:09: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 Thu, 13 Sep 2007 Volume: 11 Number: 846
Today's topics:
Re: $string =~ /$pattern/i <mritty@gmail.com>
Accessing Hash keys alphabetically <bill@ts1000.us>
Re: Accessing Hash keys alphabetically <mritty@gmail.com>
Re: Accessing Hash keys alphabetically <peter@makholm.net>
Re: Accessing Hash keys alphabetically <bill@ts1000.us>
Re: Accessing Hash keys alphabetically <s.denaxas@gmail.com>
Re: Accessing Hash keys alphabetically <bik.mido@tiscalinet.it>
Re: Accessing Hash keys alphabetically <mritty@gmail.com>
Challenge: CPU-optimized byte-wise or-equals (for a met <bik.mido@tiscalinet.it>
Re: Challenge: CPU-optimized byte-wise or-equals (for a <abigail@abigail.be>
Re: Challenge: CPU-optimized byte-wise or-equals (for a <bik.mido@tiscalinet.it>
Re: Challenge: CPU-optimized byte-wise or-equals (for a <abigail@abigail.be>
Re: Challenge: CPU-optimized byte-wise or-equals (for a <cwilbur@chromatico.net>
Re: Challenge: CPU-optimized byte-wise or-equals (for a xhoster@gmail.com
Re: Challenge: CPU-optimized byte-wise or-equals (for a <uri@stemsystems.com>
control vICQ via Perl <wolleric@gmx.de>
Re: control vICQ via Perl <wolleric@gmx.de>
Getting WWW::Mechanize to submit a form <perl4hire@softouch.on.ca>
Re: Help with compiling Math::GMP on AIX 5.3 usenet@DavidFilmer.com
Re: Help with compiling Math::GMP on AIX 5.3 (Heinrich Mislik)
Re: Help with compiling Math::GMP on AIX 5.3 <btna@terra.com>
Re: Help with compiling Math::GMP on AIX 5.3 (Heinrich Mislik)
Make money to share your videos <amitsafe1@gmail.com>
Re: removing rows based on two duplicate fileds <m@rtij.nl.invlalid>
Re: Win32::OLE->Getobject hangs?? <nobull67@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 13 Sep 2007 05:50:26 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: $string =~ /$pattern/i
Message-Id: <1189687826.041061.52330@y42g2000hsy.googlegroups.com>
On Sep 12, 7:53 pm, cracr...@cox.net wrote:
> I want a flat-out literal match where $string can contain any
> occurrence of $pattern regardless of parenthesis.
perldoc -f index
> In other words, I don't want the special characters of regular
> expressions interpreted.
perldoc -f quotemeta
Paul Lalli
------------------------------
Date: Thu, 13 Sep 2007 05:10:45 -0700
From: Bill H <bill@ts1000.us>
Subject: Accessing Hash keys alphabetically
Message-Id: <1189685445.999051.101370@57g2000hsv.googlegroups.com>
Is there any way of accessing a Hash's keys alphabetically? For
example, if I have the following:
$ARRAY{'ABC'} = "ABC";
$ARRAY{'CDE'} = "CDE";
$ARRAY{'BCD'} = "BCD";
and try to access them with a construct like this:
foreach $temp (keys(%ARRAY))
{
print "$ARRAY{$temp}\n";
}
The order I get them when I print seems to be random, or maybe FIFO,
but the way I would want to get them back would be in order based on a
sort of the keys. The way I have gotten around this is to use the
following, which could be improved with a hammer I am sure:
foreach $temp (keys(%ARRAY))
{
$dbf[@dbf] = $temp;
}
@rbf = sort @dbf;
foreach $temp (@rbf)
{
print "$ARRAY{$rbf[0]}\n";
}
This is just sample code but illustrates what I am trying to
accomplish. I am sure there is some perlish way of doing this with a
few curly braces and slashes, but can't seem to figure it out.
Bill H
------------------------------
Date: Thu, 13 Sep 2007 05:49:13 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Accessing Hash keys alphabetically
Message-Id: <1189687753.186728.65600@r29g2000hsg.googlegroups.com>
On Sep 13, 8:10 am, Bill H <b...@ts1000.us> wrote:
> Is there any way of accessing a Hash's keys alphabetically? For
> example, if I have the following:
>
> $ARRAY{'ABC'} = "ABC";
> $ARRAY{'CDE'} = "CDE";
> $ARRAY{'BCD'} = "BCD";
%ARRAY is a really bad name for a *hash*, IMO...
> and try to access them with a construct like this:
>
> foreach $temp (keys(%ARRAY))
> {
> print "$ARRAY{$temp}\n";
>
> }
>
> The order I get them when I print seems to be random
Random to you and I. Not to Perl. keys(), values(), each(), and hash-
flattening return the hash elements in the internal order used to
store the hash. Which has nothing to do with the order in which you
built the hash.
> but the way I would want to get them back would be in order based
> on a sort of the keys.
^^^^ ^^^^^
You've just made this into a Self-Answering Question. :-)
> foreach $temp (keys(%ARRAY))
> {
> $dbf[@dbf] = $temp;
> }
>
> @rbf = sort @dbf;
>
> foreach $temp (@rbf)
> {
> print "$ARRAY{$rbf[0]}\n";
> }
You're doing unnecessary steps. Why? Just sort the keys as you're
iterating through them.
foreach my $key (sort keys %ARRAY) {
print "$ARRAY{$key}\n";
}
Paul Lalli
------------------------------
Date: Thu, 13 Sep 2007 12:51:30 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: Accessing Hash keys alphabetically
Message-Id: <87ps0mranh.fsf@hacking.dk>
Bill H <bill@ts1000.us> writes:
> foreach $temp (keys(%ARRAY))
> {
> $dbf[@dbf] = $temp;
> }
This is the same as
@dbf = keys %ARRAY;
(assuming @dbf is empty)
> @rbf = sort @dbf;
And no need to store the itermediate data. So just do
@rbf = sort keys %ARRAY;
> foreach $temp (@rbf)
> {
> print "$ARRAY{$rbf[0]}\n";
> }
That doesn't work - you keep printing the same vaule. But inserting
the above and doing the right thing
for my $temp (sort keys %ARRAY) {
print "$ARRAY{$temp}\n";
}
So, these three lines should do the job.
//Makholm
------------------------------
Date: Thu, 13 Sep 2007 06:27:20 -0700
From: Bill H <bill@ts1000.us>
Subject: Re: Accessing Hash keys alphabetically
Message-Id: <1189690040.474640.197730@d55g2000hsg.googlegroups.com>
On Sep 13, 8:49 am, Paul Lalli <mri...@gmail.com> wrote:
> On Sep 13, 8:10 am, Bill H <b...@ts1000.us> wrote:
>
> > Is there any way of accessing a Hash's keys alphabetically? For
> > example, if I have the following:
>
> > $ARRAY{'ABC'} = "ABC";
> > $ARRAY{'CDE'} = "CDE";
> > $ARRAY{'BCD'} = "BCD";
>
> %ARRAY is a really bad name for a *hash*, IMO...
>
> > and try to access them with a construct like this:
>
> > foreach $temp (keys(%ARRAY))
> > {
> > print "$ARRAY{$temp}\n";
>
> > }
>
> > The order I get them when I print seems to be random
>
> Random to you and I. Not to Perl. keys(), values(), each(), and hash-
> flattening return the hash elements in the internal order used to
> store the hash. Which has nothing to do with the order in which you
> built the hash.
>
> > but the way I would want to get them back would be in order based
> > on a sort of the keys.
>
> ^^^^ ^^^^^
>
> You've just made this into a Self-Answering Question. :-)
>
> > foreach $temp (keys(%ARRAY))
> > {
> > $dbf[@dbf] = $temp;
> > }
>
> > @rbf = sort @dbf;
>
> > foreach $temp (@rbf)
> > {
> > print "$ARRAY{$rbf[0]}\n";
> > }
>
> You're doing unnecessary steps. Why? Just sort the keys as you're
> iterating through them.
>
> foreach my $key (sort keys %ARRAY) {
> print "$ARRAY{$key}\n";
>
> }
>
> Paul Lalli
As Homer Simpson says "D'0h!" Thanks Paul!
Bill H
------------------------------
Date: Thu, 13 Sep 2007 13:28:35 -0000
From: Spiros Denaxas <s.denaxas@gmail.com>
Subject: Re: Accessing Hash keys alphabetically
Message-Id: <1189690115.540943.205170@w3g2000hsg.googlegroups.com>
On Sep 13, 1:49 pm, Paul Lalli <mri...@gmail.com> wrote:
> On Sep 13, 8:10 am, Bill H <b...@ts1000.us> wrote:
>
> > Is there any way of accessing a Hash's keys alphabetically? For
> > example, if I have the following:
>
> > $ARRAY{'ABC'} = "ABC";
> > $ARRAY{'CDE'} = "CDE";
> > $ARRAY{'BCD'} = "BCD";
>
> %ARRAY is a really bad name for a *hash*, IMO...
I totally agree. I was reall disappointed when I came across a perl
tutorial page part of a university module's page and he also used
%ARRAY.
Spiros
>
> > and try to access them with a construct like this:
>
> > foreach $temp (keys(%ARRAY))
> > {
> > print "$ARRAY{$temp}\n";
>
> > }
>
> > The order I get them when I print seems to be random
>
> Random to you and I. Not to Perl. keys(), values(), each(), and hash-
> flattening return the hash elements in the internal order used to
> store the hash. Which has nothing to do with the order in which you
> built the hash.
>
> > but the way I would want to get them back would be in order based
> > on a sort of the keys.
>
> ^^^^ ^^^^^
>
> You've just made this into a Self-Answering Question. :-)
>
> > foreach $temp (keys(%ARRAY))
> > {
> > $dbf[@dbf] = $temp;
> > }
>
> > @rbf = sort @dbf;
>
> > foreach $temp (@rbf)
> > {
> > print "$ARRAY{$rbf[0]}\n";
> > }
>
> You're doing unnecessary steps. Why? Just sort the keys as you're
> iterating through them.
>
> foreach my $key (sort keys %ARRAY) {
> print "$ARRAY{$key}\n";
>
> }
>
> Paul Lalli
------------------------------
Date: Thu, 13 Sep 2007 16:51:18 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Accessing Hash keys alphabetically
Message-Id: <ljiie3pt1ua31uikmt0k2lim44qp8hukup@4ax.com>
On Thu, 13 Sep 2007 05:49:13 -0700, Paul Lalli <mritty@gmail.com>
wrote:
>%ARRAY is a really bad name for a *hash*, IMO...
Well, it is and maybe it isn't, but just to play the devil's advocate.
(Don't know if the English idiom is correct.) In fact we call them
*hashes*, but that's just because we refer to their implementation:
more correctly they are "associative arrays". Indeed "hash" is more
appealing.
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,
------------------------------
Date: Thu, 13 Sep 2007 08:16:14 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Accessing Hash keys alphabetically
Message-Id: <1189696574.805758.59490@57g2000hsv.googlegroups.com>
On Sep 13, 10:51 am, Michele Dondi <bik.m...@tiscalinet.it> wrote:
> On Thu, 13 Sep 2007 05:49:13 -0700, Paul Lalli <mri...@gmail.com>
> wrote:
>
> >%ARRAY is a really bad name for a *hash*, IMO...
>
> Well, it is and maybe it isn't, but just to play the devil's
> advocate. (Don't know if the English idiom is correct.)
It is. You speak English better than about 75% of the native-speakers
here. No worries. :-P
> In fact we call them
> *hashes*, but that's just because we refer to their implementation:
> more correctly they are "associative arrays". Indeed "hash" is more
> appealing.
Yes, but we only call regular arrays "arrays". They have no other
name. So if someone simply says to you "array", you're 99% likely to
think "array", not "associative array" or "hash".
Paul Lalli
------------------------------
Date: Thu, 13 Sep 2007 12:36:27 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)
Message-Id: <nd4ie3t1dv6sq4ae8tms59d53l1lq5ln7c@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 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,
------------------------------
Date: 13 Sep 2007 10:56:13 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)
Message-Id: <slrnfei5p1.dh.abigail@alexandra.abigail.be>
_
Michele Dondi (bik.mido@tiscalinet.it) wrote on VCXXVI September MCMXCIII
in <URL:news:nd4ie3t1dv6sq4ae8tms59d53l1lq5ln7c@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); &{%_};
------------------------------
Date: Thu, 13 Sep 2007 13:52:05 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)
Message-Id: <uk8ie310pkglfhd6n5rut3jopa6k58c58k@4ax.com>
On 13 Sep 2007 10:56:13 GMT, Abigail <abigail@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.
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,
------------------------------
Date: 13 Sep 2007 12:15:10 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)
Message-Id: <slrnfeiad1.dh.abigail@alexandra.abigail.be>
_
Michele Dondi (bik.mido@tiscalinet.it) wrote on VCXXVI September MCMXCIII
in <URL:news:uk8ie310pkglfhd6n5rut3jopa6k58c58k@4ax.com>:
$$ On 13 Sep 2007 10:56:13 GMT, Abigail <abigail@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)))))))))))))))))))))))))
------------------------------
Date: 13 Sep 2007 11:39:28 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)
Message-Id: <87fy1i377z.fsf@mithril.chromatico.net>
>>>>> "MD" == Michele Dondi <bik.mido@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
cwilbur@chromatico.net
------------------------------
Date: 13 Sep 2007 17:39:06 GMT
From: xhoster@gmail.com
Subject: Re: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)
Message-Id: <20070913133908.199$qw@newsreader.com>
Michele Dondi <bik.mido@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.
------------------------------
Date: Thu, 13 Sep 2007 16:43:21 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)
Message-Id: <x7wsuuldna.fsf@mail.sysarch.com>
>>>>> "MD" == Michele Dondi <bik.mido@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 ------ 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: Thu, 13 Sep 2007 10:23:26 -0000
From: Eric <wolleric@gmx.de>
Subject: control vICQ via Perl
Message-Id: <1189679006.710415.92260@y42g2000hsy.googlegroups.com>
Hi everyone,
I'm trying to write a rather simple Perl script to read output from
and write input to vICQ, a small ICQ console client. I know tat vICQ
itself is written in Perl, but I'm looking for a way to communicate
with other programs also, so I won't change vICQ's source.
The idea is to launch vICQ in my Perl script using IPC::start() and
then process its output (i.e. ICQ messages sent to this machine) in
intervals of, say, 30 seconds. Depending on this output I want to send
a message back to the other machine.
I read about doing this with pipes, but these don't seem to work for
me (see also http://www.thescripts.com/forum/thread49897.html), so
right now I'm using simple scalars as input/output buffers. The only
problem is that after a pump() new output (if available) is just
appended to my $out scalar. So how can I determine if there is new
output available since the last check? And will this scalar get
infinetely long, limited only by my RAM?
Thanks for any help,
Eric
p.s.: vICQ doesn't include timestamps in its output, so I can't
distinguish wether a message was sent once or repeatedly.
------------------------------
Date: Thu, 13 Sep 2007 15:10:19 -0000
From: Eric <wolleric@gmx.de>
Subject: Re: control vICQ via Perl
Message-Id: <1189696219.891767.243540@50g2000hsm.googlegroups.com>
So far, I have the following script:
use IPC::Run qw ( start );
use IO::Handle;
my @msg_name=();
my @msg_text=();
my $in,$out,$err;
my @cmd=qw( vicq -b -o -t 2 );
my $h = start
\@cmd,
\$in,
\$out,
\$err;
$in .= "msg 123456789/Listening...\n";
pump $h;
for(my $i=0;i<5;$i++) {
sleep(10);
pump $h;
@msg_name=();
@msg_text=();
while($out=~ /Instant message from (.+?):\n((.|\n)+?)\ntext_message/
g) {push(@msg_name,$1);push(@msg_text,$2);}
while($#msg_name>=0) {print shift(@msg_name)." wrote:
".shift(@msg_text)."\n";}
}
finish $h;
vICQ is started with some parameters. The script then messages another
machine that it is ready to read input. The for-loop is just for
testing purposes so my script won't run forever.
The first while-loop scans vICQ's output for an instant message event
and pushes author and text on the two arrays. The second one, also
just testing, prints out the results.
But since new output is just appended to $out, all messages that have
arrived so far are printed every 10 secs, not just the new ones.
Any ideas how to change the start() call to read sequentially?
Greets,
Eric
------------------------------
Date: Thu, 13 Sep 2007 11:58:07 -0400
From: Amer Neely <perl4hire@softouch.on.ca>
Subject: Getting WWW::Mechanize to submit a form
Message-Id: <T4dGi.359$372.298@read2.cgocable.net>
I'm trying to use this module to populate and submit a form on a remote
server, but apparently it is not doing either.
-------------------------- 8< ---------------------------
#! /usr/bin/perl
use strict;
use warnings;
use lib (
'/home/usr241/cgi-bin/PerlMods/WWW-Mechanize-1.18/lib',
'/home/usr241/cgi-bin/PerlMods/libwww-perl-5.808/lib',
'/home/usr241/cgi-bin/PerlMods/HTML-Parser-3.56/lib/'
);
use WWW::Mechanize;
use HTML::Form;
my $mech = WWW::Mechanize->new();
my $url = "http://xxx.xxx.xxx./form.aspx"; # edited
my $name="form1";
$mech->get( $url );
die "Can't even get the home page: ", $mech->response->status_line
unless $mech->success;
print "Found $url<br>\n" if $mech->success();
$mech->form($name);
die "Can't get the form name: ", $mech->response->status_line
unless $mech->success;
print "Found '$name'<br>\n" if $mech->success();
$mech->field('txtFirstName',$Firstname); # previously defined
$mech->field('txtLastName',$Lastname); # previously defined
print "Populated '$name'<br>\n" if $mech->success();
my $results = $mech->submit();
print "Submitted '$name'<br>\n" if $mech->success();
print "</body></html>\n";
-------------------------- 8< ---------------------------
When the script runs, it prints out everything as if there were no
errors. But the programmer running the form at the remote site is saying
nothing is coming through.
Can anyone see anything wrong with this code that would cause it to fail?
--
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
"Others make web sites. We make web sites work!"
------------------------------
Date: Thu, 13 Sep 2007 07:17:21 -0000
From: usenet@DavidFilmer.com
Subject: Re: Help with compiling Math::GMP on AIX 5.3
Message-Id: <1189667841.713195.133550@g4g2000hsf.googlegroups.com>
On Sep 12, 1:43 pm, btna <b...@terra.com> wrote:
> Thanks for the responses but no luck yet.
I Googled around and found an old usenet archive website with a very
similar problem:
http://www.issociate.de/board/goto/630875/GMP::Math_...PLEASE_HELP!!.html
And you appear to be the OP for that old thread. Is this the same
machine you were building on back in Feb 2005? Are some remnants of
old stuff still lying around?
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
------------------------------
Date: 13 Sep 2007 10:08:06 GMT
From: Heinrich.Mislik@univie.ac.at (Heinrich Mislik)
Subject: Re: Help with compiling Math::GMP on AIX 5.3
Message-Id: <46e90c06$0$11352$3b214f66@usenet.univie.ac.at>
In article <1189613883.180684.193860@w3g2000hsg.googlegroups.com>, btna@terra.com says...
>
>
>Hello All,
>
>I am not sure what I am missing but I think it must be something
>simple. I am trying to install Net::SSH::Perl and it requires
>Math::GMP which I have downloaded and when trying to install I get the
>following errors:
Check wether libgmp.a has objects for the correct object mode. Try:
ar -X64 t /usr/local/lib/libgmp.a
or
ar -X32 t /usr/local/lib/libgmp.a
You should get a list for -X32 since your perl is 32-bit (seen from -q32 in your CFLAGS). If nothing is there for -X32 then rebuild libgmp with OBJECT_MODE=32.
Cheers
Heinrich
--
Heinrich Mislik
Zentraler Informatikdienst der Universitaet Wien
A-1010 Wien, Universitaetsstrasse 7
Tel.: (+43 1) 4277-14056, Fax: (+43 1) 4277-9140
------------------------------
Date: Thu, 13 Sep 2007 08:27:47 -0700
From: btna <btna@terra.com>
Subject: Re: Help with compiling Math::GMP on AIX 5.3
Message-Id: <1189697267.430667.200860@d55g2000hsg.googlegroups.com>
On Sep 13, 6:08 am, Heinrich.Mis...@univie.ac.at (Heinrich Mislik)
wrote:
> In article <1189613883.180684.193...@w3g2000hsg.googlegroups.com>, b...@terra.com says...
>
>
>
> >Hello All,
>
> >I am not sure what I am missing but I think it must be something
> >simple. I am trying to install Net::SSH::Perl and it requires
> >Math::GMP which I have downloaded and when trying to install I get the
> >following errors:
>
> Check wether libgmp.a has objects for the correct object mode. Try:
>
> ar -X64 t /usr/local/lib/libgmp.a
>
> or
>
> ar -X32 t /usr/local/lib/libgmp.a
>
> You should get a list for -X32 since your perl is 32-bit (seen from -q32 in your CFLAGS). If nothing is there for -X32 then rebuild libgmp with OBJECT_MODE=32.
>
> Cheers
>
> Heinrich
>
> --
> Heinrich Mislik
> Zentraler Informatikdienst der Universitaet Wien
> A-1010 Wien, Universitaetsstrasse 7
> Tel.: (+43 1) 4277-14056, Fax: (+43 1) 4277-9140
Thanks for the reply.
David, This is a new server. I managed to get the other server to work
fine 2 years ago. This is a new server just installed with AIX 5.3
Heinrich,
I did what you suggested:
the -X32 did not return anything. However, the -X64 returned a bunch
of objects. So, I set the env variable:
# export OBJECT_MODE=32
and recompiled gmp. When I do he -X32, I still don't see anything but
now when I do -X64, I see only:
libgmp.so.3
I tried recompiling Mat::GMP and get of course the same undefined
errors.
Do you know how I could specify -q32 when compiling Math::GMP? or do
you have any other ideas for me? I am really not sure what else I can
try.
Thanks again for the replies.
BTNA
------------------------------
Date: 13 Sep 2007 15:57:01 GMT
From: Heinrich.Mislik@univie.ac.at (Heinrich Mislik)
Subject: Re: Help with compiling Math::GMP on AIX 5.3
Message-Id: <46e95dcc$0$12384$3b214f66@usenet.univie.ac.at>
In article <1189697267.430667.200860@d55g2000hsg.googlegroups.com>, btna@terra.com says...
>the -X32 did not return anything. However, the -X64 returned a bunch
>of objects. So, I set the env variable:
># export OBJECT_MODE=32
>and recompiled gmp. When I do he -X32, I still don't see anything but
>now when I do -X64, I see only:
>libgmp.so.3
Now you built a shared library but still for 64 bit.
I think gmp always builds 64 bit since this is in configure:
xlc_aix64_cflags="-O2 -q64 -qtune=pwr3 -qmaxmem=20000"
So I see two choices:
Try hacking configure to build gmp in 32bit.
Build your own perl with 64 bit. I prefer to build my own perl anyway.
good luck
Heinrich
--
Heinrich Mislik
Zentraler Informatikdienst der Universitaet Wien
A-1010 Wien, Universitaetsstrasse 7
Tel.: (+43 1) 4277-14056, Fax: (+43 1) 4277-9140
------------------------------
Date: Thu, 13 Sep 2007 03:58:08 -0700
From: amit <amitsafe1@gmail.com>
Subject: Make money to share your videos
Message-Id: <1189681088.268719.202390@r34g2000hsd.googlegroups.com>
Make money to share your videos
Goodtolove.com is sharing their 50% adsense revenue with you to post
videos of anything.
Just keep up logging in and start posting now to make money...
------------------------------
Date: Thu, 13 Sep 2007 09:41:32 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: removing rows based on two duplicate fileds
Message-Id: <pan.2007.09.13.07.38.49@rtij.nl.invlalid>
On Wed, 12 Sep 2007 23:31:58 +0000, heylow wrote:
> Gurus:
>
> I have merged /etc/passwd files many systems, and trying to master
> passwd file. I concatenated and sorted uniquely. I have the resultant
> file which looks like
>
> smith:*:100:100:8A-74(office):/home/smith:/bin/ksh
> smith:*:100:100:8A-74(office):/home/smith:/etc/fakesh <-- duplicate
> rob:*:101:101:8A-75(office):/home/smith:/bin/ksh
> don:*:102:102:B25:/home/don:/bin/fakesh
> don:*:102:102:B25:/home/don:/bin/fakesh <-- duplicate
> ele:*:255:255:A45:/home/ele:/bin/ksh
> rod:*:300:300:B456:/home/rod:/bin/ksh
>
>
> I want to delete the duplicates; that is, I want to keep only one row
> for every uid.
>
> I have tried with ksh, but in vain. Can you shed how it can be done in
> perl.
I would not use Perl for this but GNU sort:
# sort -t: -k3,3 -u passwd
M4
------------------------------
Date: Thu, 13 Sep 2007 16:49:04 -0000
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: Win32::OLE->Getobject hangs??
Message-Id: <1189702144.167735.261260@r29g2000hsg.googlegroups.com>
On Sep 12, 11:15 pm, bubslg <bub...@gmail.com> wrote:
> I've got a script that goes through a list of servers and grabs dirve
> info from them. The script usually works fine except when it hits a
> server that WMI is acting goofy on.
>
> Out of a list of ~250 servers, this call will hang on 2-3 servers.
> $WMIServices = Win32::OLE->GetObject("winmgmts:
> {impersonationLevel=impersonate}!//$Server/root/cimv2")
>
> Any ideas how to get around this? Is ther a way to force this call to
> timeout and move on?
Have you tried the usual approach? I suspect it won't work in this
case but it's worth a shot.
(See FAQ: "How do I timeout a slow event?")
------------------------------
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 V11 Issue 846
**************************************