[23579] in Perl-Users-Digest
Perl-Users Digest, Issue: 5786 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 12 14:06:42 2003
Date: Wed, 12 Nov 2003 11:05:16 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 12 Nov 2003 Volume: 10 Number: 5786
Today's topics:
"tree" view of directory <nospam@nospam.net>
Re: "tree" view of directory (William Herrera)
Re: "tree" view of directory <raisin@delete-this-trash.mts.net>
Re: "tree" view of directory (William Herrera)
[OT] Re: simplify this if loop <ak+usenet@freeshell.org>
Re: [OT] Re: simplify this if loop <trammell+usenet@hypersloth.invalid>
Re: [OT] Re: simplify this if loop <dha@panix.com>
Re: [RegEx] Replace characters <jurgenex@hotmail.com>
Re: [RegEx] Replace characters <jurgenex@hotmail.com>
Bit counting benchmarks Was: count of 1s in a binary nu (Anno Siegel)
Re: Bit counting benchmarks Was: count of 1s in a binar <shuffman@ichips.intel.com>
Re: count of 1s in a binary number <flavell@ph.gla.ac.uk>
CPAN configuration <kingsman22004@yahoo.com>
Re: CPAN configuration <usenet@morrow.me.uk>
DBD-Oracle-1.14 (diego)
Re: Fastest Perl Interpreter <trevie@cox.net>
Re: Fastest Perl Interpreter <dmcbride@naboo.to.org.no.spam.for.me>
Re: Fastest Perl Interpreter <usenet@morrow.me.uk>
fetchall_arrayref into bind_param_array (Oliver G)
Re: fetchall_arrayref into bind_param_array <usenet@morrow.me.uk>
Re: Get original destination IP and port with Linux 2.4 <usenet@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 12 Nov 2003 16:26:02 GMT
From: "Jeff Thies" <nospam@nospam.net>
Subject: "tree" view of directory
Message-Id: <uatsb.25221$9M3.14219@newsread2.news.atl.earthlink.net>
I'd like to have a tree like listing of a directories contents and it's
subdirectories. I'd like to do that with the modules from the standard perl
distribution.
It doesn't appear that I can do that with File::Find. I'm also unsure of
how to sort a readdir so that it lists directories first.
Surely this (tree view) has been done many times already!
I'm working on something like this:
(this doesn't work, it recurses back up and then forever)
sub readADir{
my $dir=shift;
print '<ul>';
opendir DIR, $dir or die "Cannot open dir $!";
my @files = readdir DIR;
closedir DIR;
foreach my $file(@files){
# my @regular_files=();my @directories=();
if(-d "$dir/$file"){unless($file=~/^\./){push @directories, "$dir/$file"}}
if(-f "$dir/$file"){push @regular_files, $file;}
}
@directories=sort @directories;
foreach my $directory(@directories){
if($dir ne $directory){readADir($directory)};
}
@regular_files=sort @regular_files;
foreach my $regular_file(@regular_files){
print qq{<li> $regular_file </li>};
}
print '</ul>';
}
Jeff
------------------------------
Date: Wed, 12 Nov 2003 17:12:35 GMT
From: wherrera@lynxview.com (William Herrera)
Subject: Re: "tree" view of directory
Message-Id: <3fb26960.138575128@news2.news.adelphia.net>
On Wed, 12 Nov 2003 16:26:02 GMT, "Jeff Thies" <nospam@nospam.net> wrote:
> I'd like to have a tree like listing of a directories contents and it's
>subdirectories. I'd like to do that with the modules from the standard perl
>distribution.
>
> It doesn't appear that I can do that with File::Find. I'm also unsure of
>how to sort a readdir so that it lists directories first.
>
> Surely this (tree view) has been done many times already!
>
http://www.cpan.org/modules/by-authors/id/R/RC/RCLAMP/File-Slurp-Tree-1.22.tar.gz
---
Use the domain skylightview (dot) com for the reply address instead.
------------------------------
Date: Wed, 12 Nov 2003 11:29:13 -0600
From: Master Web Surfer <raisin@delete-this-trash.mts.net>
Subject: Re: "tree" view of directory
Message-Id: <MPG.1a1c29e5126d552c9896ce@news.mts.net>
[This followup was posted to comp.lang.perl.misc]
In article <uatsb.25221$9M3.14219@newsread2.news.atl.earthlink.net>,
nospam@nospam.net says...
> I'd like to have a tree like listing of a directories contents and it's
> subdirectories. I'd like to do that with the modules from the standard perl
> distribution.
>
> It doesn't appear that I can do that with File::Find. I'm also unsure of
> how to sort a readdir so that it lists directories first.
>
> Surely this (tree view) has been done many times already!
>
> I'm working on something like this:
>
> (this doesn't work, it recurses back up and then forever)
>
> sub readADir{
> my $dir=shift;
> print '<ul>';
>
> opendir DIR, $dir or die "Cannot open dir $!";
> my @files = readdir DIR;
> closedir DIR;
>
> foreach my $file(@files){
> # my @regular_files=();my @directories=();
> if(-d "$dir/$file"){unless($file=~/^\./){push @directories, "$dir/$file"}}
> if(-f "$dir/$file"){push @regular_files, $file;}
> }
>
> @directories=sort @directories;
> foreach my $directory(@directories){
> if($dir ne $directory){readADir($directory)};
> }
>
> @regular_files=sort @regular_files;
> foreach my $regular_file(@regular_files){
> print qq{<li> $regular_file </li>};
> }
> print '</ul>';
> }
>
> Jeff
Here's some old perl code I have lying around that should do the trick
for you.
#!/usr/bin/perl -w
use English;
sub search_dir
{
local ( $dirname ) = @_;
local ( @entries , $entry , $path , @dirs_list , $dircount ,
@files );
if ( ! opendir(DIR,$dirname) ) {
print STDERR "opendir failed for \"$dirname\" : $!\n";
return 0;
} # IF
@entries = readdir DIR;
closedir DIR;
@dirs_list = ();
@files = ();
$dircount = 0;
foreach $entry ( @entries ) {
if ( $entry eq "." || $entry eq ".." ) {
next;
} # IF
$path = sprintf "%s\\%s",$dirname,$entry;
if ( -d $path && $entry ne "." && $entry ne ".." ) {
$dircount += 1;
push(@dirs_list,$entry);
print "$path [dir]\n";
} # IF
else {
push @files,$entry;
} # ELSE
} # FOREACH
if ( 0 < @files ) {
foreach $entry ( @files ) {
print $dirname,"\\",$entry,"\n";
} # FOREACH
} # IF
foreach $entry ( @dirs_list ) {
$dircount += &search_dir($dirname."\\".$entry);
} # FOREACH;
return $dircount;
} # end of search_dir
MAIN:
{
local ( $dirname , $count );
$dirname = ( $#ARGV >= 0 ) ? $ARGV[0] : ".";
print "Directories under \"$dirname\"\n";
$count = &search_dir($dirname);
print "\n$count total directories\n";
exit 0;
} # end of MAIN
------------------------------
Date: Wed, 12 Nov 2003 18:33:50 GMT
From: wherrera@lynxview.com (William Herrera)
Subject: Re: "tree" view of directory
Message-Id: <3fb27d10.143616669@news2.news.adelphia.net>
On Wed, 12 Nov 2003 16:26:02 GMT, "Jeff Thies" <nospam@nospam.net> wrote:
> I'd like to have a tree like listing of a directories contents and it's
>subdirectories. I'd like to do that with the modules from the standard perl
>distribution.
>
> It doesn't appear that I can do that with File::Find. I'm also unsure of
>how to sort a readdir so that it lists directories first.
>
> Surely this (tree view) has been done many times already!
Here's another that does not slurp files, just directories:
use Class::Tree;
my $dir1 = '/opt';
my $tree1 = new Class::Tree;
$tree1 -> buildDirTree($dir1, ['CVS']);
print $tree1 -> writeTree();
---
Use the domain skylightview (dot) com for the reply address instead.
------------------------------
Date: Wed, 12 Nov 2003 16:26:55 +0000 (UTC)
From: Andreas Kahari <ak+usenet@freeshell.org>
Subject: [OT] Re: simplify this if loop
Message-Id: <slrnbr4nqe.8dq.ak+usenet@mx.freeshell.org>
In article <pan.2003.11.12.11.57.38.116144@aursand.no>, Tore Aursand wrote:
> On Wed, 12 Nov 2003 04:45:29 +0000, Uri Guttman wrote:
>>> Luckily, I was wrong. :-) Caught myself in commenting out the line
>
>> shouldn't that be commentating out the line? :)
>
> Uhm, yeah. Maybe. Take a look at the two last characters in my email
> address. :-)
Hmm... I believe Tore was right. The word "commenting" means
"to annotate" or "to make a comment", while "commentating" means
"to serve as a commentator" or "to make a running commentary
on".
...according to "dictionary.reference.com".
--
Andreas Kähäri
------------------------------
Date: Wed, 12 Nov 2003 16:41:21 +0000 (UTC)
From: "John J. Trammell" <trammell+usenet@hypersloth.invalid>
Subject: Re: [OT] Re: simplify this if loop
Message-Id: <slrnbr4olh.eoj.trammell+usenet@hypersloth.el-swifto.com.invalid>
On Wed, 12 Nov 2003 16:26:55 +0000 (UTC), Andreas Kahari wrote:
> In article <pan.2003.11.12.11.57.38.116144@aursand.no>, Tore Aursand wrote:
>> On Wed, 12 Nov 2003 04:45:29 +0000, Uri Guttman wrote:
>>>> Luckily, I was wrong. :-) Caught myself in commenting out the line
>>
>>> shouldn't that be commentating out the line? :)
>>
>> Uhm, yeah. Maybe. Take a look at the two last characters in my email
>> address. :-)
>
> Hmm... I believe Tore was right. The word "commenting" means
> "to annotate" or "to make a comment", while "commentating" means
> "to serve as a commentator" or "to make a running commentary
> on".
>
You know the sad tale of the Potato Princess who wanted to
marry Howard Cosell?
She couldn't, becaues he was just a common tator.
$rimshot->();
------------------------------
Date: Wed, 12 Nov 2003 18:00:59 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: [OT] Re: simplify this if loop
Message-Id: <slrnbr4taq.83m.dha@panix2.panix.com>
In article
<slrnbr4olh.eoj.trammell+usenet@hypersloth.el-swifto.com.invalid>, John
J. Trammell wrote:
> You know the sad tale of the Potato Princess who wanted to
> marry Howard Cosell?
>
> She couldn't, becaues he was just a common tator.
>
> $rimshot->();
Ok, first of all, ow.
Second, shouldn't that be $Percussion->rimshot() ? :-)
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
All right! So I'm the daughter of poison gas!
- Sybil Crane, The Big Bus
------------------------------
Date: Wed, 12 Nov 2003 14:51:35 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: [RegEx] Replace characters
Message-Id: <XNrsb.42041$p9.16823@nwrddc02.gnilink.net>
Bouba654 wrote:
> I would like to write a regex for mod_rewrite in order to replace all
> "?" by "!". Do you think it's possible ?
No idea what mod_rewrite is, but why do you want to use a regexp? The
question mark is a single character that you already know, no need to launch
the big RE shotgun. A simple
tr /?/!/
is sufficient and will be significantly faster, too.
jue
------------------------------
Date: Wed, 12 Nov 2003 15:39:10 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: [RegEx] Replace characters
Message-Id: <yussb.33892$E9.19894@nwrddc01.gnilink.net>
Jürgen Exner wrote:
> Bouba654 wrote:
>> I would like to write a regex for mod_rewrite in order to replace all
>> "?" by "!". Do you think it's possible ?
>
> No idea what mod_rewrite is, but why do you want to use a regexp? The
> question mark is a single character that you already know, no need to
> launch the big RE shotgun. A simple
> tr /?/!/
> is sufficient and will be significantly faster, too.
Actually I just noticed that I didn't answer your original question:
>> [...] write a regex [...] to replace all "?" by "!". Do you think it's
possible ?
No, this is not possible.
Regular expressions only match text, they do not replace anything.
If you want to replace text then you must use a function or operator that
replaces text, e.g. s or tr or an assignment or something similar.
jue
------------------------------
Date: 12 Nov 2003 17:13:07 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Bit counting benchmarks Was: count of 1s in a binary number
Message-Id: <botpn3$eek$1@mamenchi.zrz.TU-Berlin.DE>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote in comp.lang.perl.misc:
> Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote in comp.lang.perl.misc:
> > [A complimentary Cc of this posting was sent to
> > Anno Siegel
> > <anno4000@lublin.zrz.tu-berlin.de>], who wrote in article
> > <boj8vt$iui$1@mamenchi.zrz.TU-Berlin.DE>:
> > > > sub size1 {
> > > > # Recursive approach, terse and elegant IMHO.
> > > > # An iterative one is OK as well.
> > > > my $n=shift;
> > > > return 0 unless $n;
> > > > return ($n&1) + size1($n>>1);
> > > > }
> >
> > > That counts the bits of an n-bit number in n steps. There is an old trick
> > > in the dying art of bit-fiddling that allows to count them in as many steps
> > > as there are one-bits. That is a significant advantage if the numbers
> > > involved are small (or sparse, bit-wise).
> >
> > Should be quite sparse to beat something like this:
> >
> > sub count_bits ($) {
> > my $x = shift;
> > my $shift = 1;
> > for my $mask (0x55555555, 0x33333333, 0x0f0f0f0f, 0x00ff00ff,
> 0x0000ffff) {
> > $x = ($x & $mask) + (($x >> $shift) & $mask);
> > $shift *= 2;
> > }
> > $x;
> > }
> >
> > print count_bits 0b111110010111000111101010001001;
>
> Yikes, what's that? Wait... it's considering $x as a series of $shift-bit
> ($shift = 1, 2, 4,..) numbers and makes room for overflow using the mask
> and doing every addition in two steps. I hadn't seen this before, thanks
> for bringing it up.
>
> I'll do some benchmarks when I get a minute. I'm curious how it compares
> with a lookup table.
Okay, here are the promised benchmarks.
Rate direct decrement ilya table
direct 18877/s -- -50% -65% -77%
decrement 37451/s 98% -- -30% -54%
ilya 53439/s 183% 43% -- -34%
table 80850/s 328% 116% 51% --
The four routines all count the bits in a 32 bit integer.
direct - uses a plain shift-and-count approach
decrement - picks the MSB through the $x & ($x - 1) technique
ilya - the method Ilya presented (and Alan recognized)
table - uses a one-byte lookup table
Complete code below.
So Ilya's code is indeed fastest among those that actually do the counting,
but a lookup table beats them all.
Anno
-------------------------------------------------------------------
#!/usr/local/bin/perl
use strict; use warnings;
use Benchmark qw( :all);
use Text::Table;
goto bench;
my $tb = Text::Table->new( qw( n bin), \' | ',
qw( direct decrement ilya table)
);
for ( 1 .. 3 ) {
my $x = int rand( 2**32);
$tb->add( $x, sprintf( "%32b", $x),
direct( $x), decrement( $x), ilya( $x), table( $x));
}
print $tb;
exit;
bench:
cmpthese( -5, {
direct => 'direct( int rand 2**32)',
decrement => 'decrement( int rand 2**32)',
ilya => 'ilya( int rand 2**32)',
table => 'table( int rand 2**32)',
});
###################################################################
# bit counting
sub direct {
my $x = shift;
my $count = 0;
while ( $x ) {
$count += $x & 1;
$x >>= 1;
}
$count;
}
sub decrement {
my $x = shift;
my $count = 0;
while ( $x ) {
$count++;
$x &= $x - 1;
}
$count;
}
sub ilya {
my $x = shift;
my $shift = 1;
for my $mask (0x55555555, 0x33333333, 0x0f0f0f0f, 0x00ff00ff, 0x0000ffff) {
$x = ($x & $mask) + (($x >> $shift) & $mask);
$shift *= 2;
}
$x;
}
my @table;
BEGIN {
$table[ $_] = direct( $_) for 0 .. 255;
}
sub table {
my $x = shift;
my $count = 0;
while ( $x ) {
$count += $table[ $x & 255];
$x >>= 8;
}
$count;
}
------------------------------
Date: 12 Nov 2003 09:40:19 -0800
From: Sam Huffman <shuffman@ichips.intel.com>
Subject: Re: Bit counting benchmarks Was: count of 1s in a binary number
Message-Id: <po865hptri4.fsf@pdxlx1644.pdx.intel.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> Okay, here are the promised benchmarks.
>
> Rate direct decrement ilya table
> direct 18877/s -- -50% -65% -77%
> decrement 37451/s 98% -- -30% -54%
> ilya 53439/s 183% 43% -- -34%
> table 80850/s 328% 116% 51% --
An unrolled version of ilya is even better. I found this c code snippet
somewhere (long since forgotten the source), and have used it extensively;
converted to perl:
sub unrolled
{
my $n = shift;
$n = ($n & 0x55555555) + (($n & 0xaaaaaaaa) >> 1);
$n = ($n & 0x33333333) + (($n & 0xcccccccc) >> 2);
$n = ($n & 0x0f0f0f0f) + (($n & 0xf0f0f0f0) >> 4);
$n = ($n & 0x00ff00ff) + (($n & 0xff00ff00) >> 8);
$n = ($n & 0x0000ffff) + (($n & 0xffff0000) >> 16);
$n;
}
On my machine, with 5.8.0, this beats the table by 16%:
Rate direct decrement ilya table unrolled
direct 55042/s -- -47% -56% -76% -79%
decrement 104462/s 90% -- -16% -54% -60%
ilya 125005/s 127% 20% -- -45% -52%
table 226603/s 312% 117% 81% -- -14%
unrolled 261986/s 376% 151% 110% 16% --
Sam
------------------------------
Date: Wed, 12 Nov 2003 15:28:20 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: count of 1s in a binary number
Message-Id: <Pine.LNX.4.53.0311121521560.6274@ppepc56.ph.gla.ac.uk>
On Wed, 12 Nov 2003, Ilya Zakharevich wrote:
> sub count_bits ($) {
> my $x = shift;
> my $shift = 1;
> for my $mask (0x55555555, 0x33333333, 0x0f0f0f0f, 0x00ff00ff, 0x0000ffff) {
> $x = ($x & $mask) + (($x >> $shift) & $mask);
> $shift *= 2;
> }
> $x;
> }
Ah, nostalgia. I programmed something very close that in IBM
assembler many years back, in connection with a bubble-chamber film
scanning program.
thanks!
------------------------------
Date: Thu, 13 Nov 2003 04:57:45 +1100
From: King <kingsman22004@yahoo.com>
Subject: CPAN configuration
Message-Id: <3FB27499.3080704@yahoo.com>
Hello
I need to get a module off CPAN so
# /usr/local/bin/perl -MCPAN -e 'install module::name"'
Are you ready for manual configuration? [yes]
CPAN build and cache directory? [/root/.cpan]
Cache size for build directory (in MB)? [10]
Perform cache scanning (atstart or never)? [atstart]
Cache metadata (yes/no)? [yes]
Your terminal expects ISO-8859-1 (yes/no)? [yes]
Policy on building prerequisites (follow, ask or ignore)? [ask]
Where is your gzip program? [/bin/gzip]
Where is your tar program? [/bin/tar]
Warning: unzip not found in PATH
# apt-get install unzip
Where is your unzip program? [] /usr/bin/unzip
Where is your make program? [/usr/bin/make]
Where is your lynx program? [/usr/bin/lynx]
Where is your wget program? [/usr/bin/wget]
Warning: ncftpget not found in PATH
Where is your ncftpget program? []
# locate ncftpget
#
should I pass on this option till I need to install this ncftpget?
thanks
------------------------------
Date: Wed, 12 Nov 2003 18:23:09 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: CPAN configuration
Message-Id: <bottqd$1hg$1@wisteria.csv.warwick.ac.uk>
news@group.com wrote:
> Hello
> I need to get a module off CPAN so
> # /usr/local/bin/perl -MCPAN -e 'install module::name"'
> Are you ready for manual configuration? [yes]
> CPAN build and cache directory? [/root/.cpan]
> Cache size for build directory (in MB)? [10]
> Perform cache scanning (atstart or never)? [atstart]
> Cache metadata (yes/no)? [yes]
> Your terminal expects ISO-8859-1 (yes/no)? [yes]
> Policy on building prerequisites (follow, ask or ignore)? [ask]
> Where is your gzip program? [/bin/gzip]
> Where is your tar program? [/bin/tar]
> Warning: unzip not found in PATH
> # apt-get install unzip
> Where is your unzip program? [] /usr/bin/unzip
> Where is your make program? [/usr/bin/make]
> Where is your lynx program? [/usr/bin/lynx]
> Where is your wget program? [/usr/bin/wget]
> Warning: ncftpget not found in PATH
> Where is your ncftpget program? []
> # locate ncftpget
> #
>
> should I pass on this option till I need to install this ncftpget?
You don't need ncftpget... CPAN.pm builds up a list of all the
different ways you have to download a file, so it can try others if
one fails. You've got wget, so you don't need ncftpget. The same
applies to most of the other questions: if CPAN.pm can't find a
program, it likely isn't essential.
Ben
--
I've seen things you people wouldn't believe: attack ships on fire off the
shoulder of Orion; I've watched C-beams glitter in the darkness near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die. |-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-| ben@morrow.me.uk
------------------------------
Date: 12 Nov 2003 06:20:20 -0800
From: pico72@libero.it (diego)
Subject: DBD-Oracle-1.14
Message-Id: <37c6317c.0311120620.4e8b8ce0@posting.google.com>
Hi,
I'm not able to create the Makefile for DBD module. The OS is winXP,
I'm using ActivePerl 5.8.0 and DBD-Oracle-1.14. DBI are already
installed. Oracle Home is c:\oracle\ora92. Perl is in c:\Perl.
When I type:
perl Makefile.pl
the console output is following:
Using DBI 1.38 installed in C:/Perl/site/lib/auto/DBI
Configuring DBD::Oracle ...
>>> Remember to actually *READ* the README file!
Especially if you have any problems.
Using Oracle in C:/oracle/ora92
Found header files in rdbms/demo.
*********************************************************
I can't find the header files I need in your Oracle installation. You
probably need to install some more Oracle components. I'll keep going,
but the compile will probably fail. See README.clients for more
information.
*********************************************************
Found oci directory
Using OCI directory 'oci'
Found oci/lib/MSVC/oramts.lib library
*** Warning: Colons in the current directory path
(C:/perl/DBDOracle114) may cause problems
Unable to find required Oracle OCI files for the build. Please check
That you have your OCI installed in your oracle home (C:/oracle/ora9)
Directory and that it has the following files (and probably more):
C:/oracle/ora92\oci\include\oratypes.h
C:/oracle/ora92\oci\lib\MSVC\.lib
Please install OCI or send comments back to dbi-users@perl.org
If you have an OCI directory other than oci.
At Makefile.pl line 263
THANK YOU IN ADVANCE FOR THE HELP. PLEASE DON'T LET ME ALONE!!!
------------------------------
Date: Wed, 12 Nov 2003 07:52:46 -0700
From: "Michael J. Astrauskas" <trevie@cox.net>
Subject: Re: Fastest Perl Interpreter
Message-Id: <ZOrsb.21854$0K6.11260@fed1read06>
Darin McBride wrote:
> Michael J. Astrauskas wrote:
>
>>I'm attempting build a system that needs to run a perl script very
>>quickly. There will be no disk access, but the system will be doing an
>>intense amount of network and processor work. Is there any particular
>>processor architecture (32-bit AMD/Intel, Opteron, Sun, Apple, etc.),
>>operating system, and interpreter that are known to be the most powerful
>>combination?
>
> My guess, then, is that you want something that has a big network pipe
> and a fast processor. Perl is perl is perl - the only difference
> between the platforms is going to be the C optimiser that you compile
> perl itself with. Well, maybe not *only*, but that will have the
> largest effect other than the hardware itself.
It's for a contest and the requirement is actually dual gigabit Ethernet
ports.
> For example, Intel promises a percentage-boost simply by compiling with
> their Proton or Electron compilers over using MSVC or gcc on the same
> platform. If you compile perl 5.8.1 with the Electron compiler on
> Linux/ia32, you'll probably be doing alright for your system.
I'm definitely going to keep this in mind. Thank you.
>>My current idea is to use a dual Xeon with a gigabyte ethernet port and
>>at least 2 GB of RAM.
>
> As soon as you have multiple CPUs, you'll only see any benefits if you
> actually have a multi-threaded or multi-process system running. That
> is, at least one thread of activity per CPU. If your program can only
> do one thing at a time, that second CPU will be 90%+ wasted.
>
> If, however, your program can run multithreaded (dangerous in perl,
> last I heard) or multiprocess (i.e. fork() and do stuff in the child
> process), then by all means go with the SMP setup. Note that perl
> likes fork()'s, and Windows doesn't, so you might be best off here
> going with Linux instead of Windows.
The script is single-threaded but there will be many instances of it
running.
>>Thank you for any advice, recommendations, and pointers!
>
> As long as you're going with commodity hardware, dual P4s will probably
> saturate your gigabit ethernet. Depending on what you're doing, you
> may want dual gigabit ethernet cards, and go with 4 or more Pentium4's
> for better throughput. This only helps, of course, if the data you're
> processing can come in from multiple networks or subnets. It can
> eliminate a hop for people coming in from more than one router away.
I was looking at some benchmarks and P4s did quite well, but dual
Opterons did better in most regards (over dual Xeons, as well). Not all,
though, which makes my decision all that much harder.
--
- Michael J. Astrauskas
------------------------------
Date: Wed, 12 Nov 2003 15:29:11 GMT
From: Darin McBride <dmcbride@naboo.to.org.no.spam.for.me>
Subject: Re: Fastest Perl Interpreter
Message-Id: <blssb.376694$pl3.89640@pd7tw3no>
Michael J. Astrauskas wrote:
> Darin McBride wrote:
>
>> Michael J. Astrauskas wrote:
>>
>>>I'm attempting build a system that needs to run a perl script very
>>>quickly. There will be no disk access, but the system will be doing an
>>>intense amount of network and processor work. Is there any particular
>>>processor architecture (32-bit AMD/Intel, Opteron, Sun, Apple, etc.),
>>>operating system, and interpreter that are known to be the most powerful
>>>combination?
>>
>> My guess, then, is that you want something that has a big network pipe
>> and a fast processor. Perl is perl is perl - the only difference
>> between the platforms is going to be the C optimiser that you compile
>> perl itself with. Well, maybe not *only*, but that will have the
>> largest effect other than the hardware itself.
>
> It's for a contest and the requirement is actually dual gigabit Ethernet
> ports.
I see I nailed that one already by suggesting it. ;->
>> For example, Intel promises a percentage-boost simply by compiling with
>> their Proton or Electron compilers over using MSVC or gcc on the same
>> platform. If you compile perl 5.8.1 with the Electron compiler on
>> Linux/ia32, you'll probably be doing alright for your system.
>
> I'm definitely going to keep this in mind. Thank you.
Just note that these compilers cost $$$, whereas MSVC only costs $, and
gcc, of course, has no cost. ;->
>>>My current idea is to use a dual Xeon with a gigabyte ethernet port and
>>>at least 2 GB of RAM.
>>
>> As soon as you have multiple CPUs, you'll only see any benefits if you
>> actually have a multi-threaded or multi-process system running. That
>> is, at least one thread of activity per CPU. If your program can only
>> do one thing at a time, that second CPU will be 90%+ wasted.
>>
>> If, however, your program can run multithreaded (dangerous in perl,
>> last I heard) or multiprocess (i.e. fork() and do stuff in the child
>> process), then by all means go with the SMP setup. Note that perl
>> likes fork()'s, and Windows doesn't, so you might be best off here
>> going with Linux instead of Windows.
>
> The script is single-threaded but there will be many instances of it
> running.
That is multiprocess. Obviously, I should have used "e.g." rather than
"i.e.". Thus, SMP is helpful. If you can change the code slightly to
use fork after loading all the modules and you can use Linux, I would
say that this would get a small speed boost as your script would only
get compiled once for all the processes, and this may help the OS
overlap things in memory for more speed boosts during runtime (fewer
cache misses, possibly).
>>>Thank you for any advice, recommendations, and pointers!
>>
>> As long as you're going with commodity hardware, dual P4s will probably
>> saturate your gigabit ethernet. Depending on what you're doing, you
>> may want dual gigabit ethernet cards, and go with 4 or more Pentium4's
>> for better throughput. This only helps, of course, if the data you're
>> processing can come in from multiple networks or subnets. It can
>> eliminate a hop for people coming in from more than one router away.
>
> I was looking at some benchmarks and P4s did quite well, but dual
> Opterons did better in most regards (over dual Xeons, as well). Not all,
> though, which makes my decision all that much harder.
Yes - unless you can get the hardware side-by-side running your
application, it'll be a fair bit of guesswork.
Best of luck!
------------------------------
Date: Wed, 12 Nov 2003 17:00:21 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Fastest Perl Interpreter
Message-Id: <botov5$sh3$3@wisteria.csv.warwick.ac.uk>
Darin McBride <dmcbride@naboo.to.org.no.spam.for.me> wrote:
> Michael J. Astrauskas wrote:
> > Darin McBride wrote:
> >> For example, Intel promises a percentage-boost simply by compiling with
> >> their Proton or Electron compilers over using MSVC or gcc on the same
> >> platform. If you compile perl 5.8.1 with the Electron compiler on
> >> Linux/ia32, you'll probably be doing alright for your system.
> >
> > I'm definitely going to keep this in mind. Thank you.
>
> Just note that these compilers cost $$$, whereas MSVC only costs $, and
> gcc, of course, has no cost. ;->
Is there significant advantage to using Intel's free icc over gcc?
Ben
--
"If a book is worth reading when you are six, * ben@morrow.me.uk
it is worth reading when you are sixty." - C.S.Lewis
------------------------------
Date: 12 Nov 2003 07:19:19 -0800
From: oliver.gassner@web.de (Oliver G)
Subject: fetchall_arrayref into bind_param_array
Message-Id: <eabb4cb1.0311120719.2095e410@posting.google.com>
Hey Folk,
i have to do a Job to extract Data from one Database into another.
So i thing this is a Job for Perl. I make a fetchall_arrayref then i
insert this block into the other Database with bind_param_array. Now i
have the Array of Arrays but i can't extract an Array of Column to use
bind_param_array.
Have any one a Idea?
Any Hint welcome!
Olli
------------------------------
Date: Wed, 12 Nov 2003 17:02:37 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: fetchall_arrayref into bind_param_array
Message-Id: <botp3d$sh3$5@wisteria.csv.warwick.ac.uk>
oliver.gassner@web.de (Oliver G) wrote:
> Hey Folk,
> i have to do a Job to extract Data from one Database into another.
> So i thing this is a Job for Perl. I make a fetchall_arrayref then i
> insert this block into the other Database with bind_param_array. Now i
> have the Array of Arrays but i can't extract an Array of Column to use
> bind_param_array.
>
> Have any one a Idea?
>
> Any Hint welcome!
Hint: try posting some code, and telling us what it doesn't do that
you want it to.
Ben
--
Although few may originate a policy, we are all able to judge it.
- Pericles of Athens, c.430 B.C.
ben@morrow.me.uk
------------------------------
Date: Wed, 12 Nov 2003 16:49:30 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Get original destination IP and port with Linux 2.4 iptables redirect?
Message-Id: <botoaq$sh3$1@wisteria.csv.warwick.ac.uk>
Lincoln Yeoh <junkto@tm.net.my> wrote:
> Say I use iptables to redirect tcp connections to my perl proxy
> servers. How then do I get the original destination IP address and tcp
> port?
>
> On FreeBSD I just use ipfw and fwd and then following works:
> $daddr=$client->sockhost;
> $dport=$client->sockport;
>
> And then my various proxies work transparently.
>
> But on Linux I'm supposed to use some FD options:
> e.g.
> getsockopt(fd, SOL_IP, SO_ORIGINAL_DST, &dst_addr, &slen)
>
> What's a good way to do this with perl? Working examples would be very
> helpful.
>
> I've tried perl's getsockopt but replacing OPTNAME with
> SO_ORIGINAL_DST doesn't work - it's not defined.
>
> perl -f getsockopt
> getsockopt SOCKET,LEVEL,OPTNAME
>
> I've tried specifying a numerical 80 for OPTNAME but not sure how to
> get the address etc.
The call in Perl is the same as C, except that return values are
returned instead of being passed by reference. So
use Socket qw/inet_ntoa/;
my $packed_addr = getsockopt $SOCK, SOL_IP, SO_ORIGINAL_DST;
my $addr = inet_ntoa $packed_addr;
(untested) should work. To get the values of the constants you will
need to poke around in your headers... on my machine, SOL_IP is
defined to be 0 in <bits/in.h> and SO_ORIGINAL_DST to be 80 in
<linux/netfilter_ipv4/ip_nat.h>. You could try throwing those headers
at h2ph, just for a laugh :), or you could just put use constant
statements at the top of your program.
Ben
--
EAT
KIDS (...er, whoops...)
FOR ben@morrow.me.uk
99p
------------------------------
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.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 5786
***************************************