[8740] in Perl-Users-Digest
Perl-Users Digest, Issue: 2357 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 18 03:07:28 1998
Date: Sat, 18 Apr 98 00:00:49 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 18 Apr 1998 Volume: 8 Number: 2357
Today's topics:
Re: Carriage return/line feed in text files dennis_marti@yahoo.com
Re: cgi using perl <gurun@acc.umu.se>
Re: Easy way to count lines in a file (Craig Berry)
Re: Fastest "smallest power of 2 >= N" in Perl? <ljz@asfast.com>
Re: Fastest "smallest power of 2 >= N" in Perl? <ljz@asfast.com>
Re: Fastest "smallest power of 2 >= N" in Perl? <lr@hpl.hp.com>
Re: Fastest "smallest power of 2 >= N" in Perl? <lr@hpl.hp.com>
function pointers (Richard Pocklington)
Re: function pointers <ebohlman@netcom.com>
Re: how to remove blanks? <lr@hpl.hp.com>
Re: how to remove blanks? <zenin@archive.rhps.org>
Re: how to remove blanks? (Craig Berry)
Re: how to remove blanks? (Mike Heins)
Perl Performace: CPU, and System Resource Usage. phdss@writeme.comm
Re: Perl vs. Java <snay@primenet.com>
Re: Perl vs. Java <zenin@archive.rhps.org>
Perl, MySQL on my home PC <inept@mail.anet-stl.com>
Retrieve HTML FORM POST info within CGI Perl Program <snay@primenet.com>
Re: Retrieve HTML FORM POST info within CGI Perl Progra <snay@primenet.com>
Re: Retrieve HTML FORM POST info within CGI Perl Progra <Pat_kane@compuserve.com>
Re: Server Side Include <gwynne@utkux.utk.edu>
Re: Snobby news group <snay@primenet.com>
uninitialized <STDIN> chunk 1. ???? <toby@he-net.demon.co.uk>
Re: Wanna laugh? (My First cgi.pm Script) (Craig Berry)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 17 Apr 1998 23:45:32 -0600
From: dennis_marti@yahoo.com
Subject: Re: Carriage return/line feed in text files
Message-Id: <6h9b5c$5l0$1@nnrp1.dejanews.com>
In article <6h88mt$b0n@fridge.shore.net>,
"Grinch" <grinch@whoville.com> wrote:
> chomp() removes all trailing carriage returns and/or linefeeds.
No it doesn't.
$s = "one\n\n\n\n";
print length($s), "\n"; # prints 7
chomp $s;
print length($s), "\n"; # prints 6
Dennis
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Sat, 18 Apr 1998 07:58:09 +0200
From: N i c l a s O l o f s s o n <gurun@acc.umu.se>
Subject: Re: cgi using perl
Message-Id: <353840F1.C052380C@acc.umu.se>
Abigail wrote:
> There's no Perl specific aspect in your question.
[snip]
> Ask in the CGI group. Or better, read the FAQ.
Perl FAQ really got to be something. Every answer beginning with "no
Perl specific" seem to refer to the FAQ. I'll bet it's a very fine FAQ,
since it seem to answer all Q possible, Perl specific or not. Maybe
that's why you never tell people where it is?
> I'm pretty sure your question is answered there.
"Pretty sure"? Don't you know? RTFM until you know then ;)
/Niclas
------------------------------
Date: 18 Apr 1998 05:56:14 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Easy way to count lines in a file
Message-Id: <6h9f9u$g8$1@marina.cinenet.net>
Tommy (tkho@technologist.com) wrote:
: how about
:
: @Lines= <ACCESS>
: $NumOfLines= $#Lines;
If for some reason you want your line count to be low by one, that's a
very good approach. If you prefer an accurate line count, replace $#Lines
(the highest index in @Lines) with just plane @Lines (in a scalar context,
the number of elements in @Lines).
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 18 Apr 1998 00:00:49 -0400
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: Fastest "smallest power of 2 >= N" in Perl?
Message-Id: <ltlnt3vkwe.fsf@asfast.com>
cbarron3@ix.netcom.com (carl barron) writes:
> Tom Rokicki <rokicki@cello.hpl.hp.com> wrote:
>
> > This is what I get:
> >
> > sub mySmallestPowerOfTwoGE {
> > use integer;
> > my $a=sprintf("%o",(shift)-1);
> > return 1<<(3*length($a)+(-3,-2,-1,-1,0,0,0,0)[ord($a)-48]) ;
> > }
>
> int power_2(unsigned long x)
> {
> int nbits = BITS_PER_LONG;
>
>
> while(x>>1) --nbits;
> return ++nbits;
> }
Carl, your simple and elegent solution returns the number of bits, not
the power of two itself. You'd have to do a `return 1<<(++nbits)'.
Also, I'm happy to see Tom Rokicki's excellent solution. I was hoping
there would a solution that would make use of Perl's unique features,
and that went beyond the usual integer-bit-manipulation approaches
that are used in C and certain other languages. Yours, Tom, fulfilled
my hopes.
After looking at Tom's routine, I realized that I could streamline it
slightly by using subtraction instead of addition and by getting rid
of the "-48". This shaved a bit more time off of it. See below for
the routine named `variation_on_toms'.
I also shaved a tiny bit off my original routine's timing by getting
rid of the bit-flipped negative value in the `while' statement and
replacing it with `$value &= ($value - 1)'. I call this version
`lloyds_new_version'.
I ran all four versions (my modified version, Tom's original one, my
variation on Tom's, and the Perl-ized version of Carl Barron's which
returns 2 raised to the power, instead of just the power itself). The
results follow. You'll see that the variation on Tom's is the fastest
of the four.
Also note that I tested each one in a loop, passing it a range of
values from 0 through (2^15 + 1). I figured that this would give more
representative results than simply repeatedly feeding the same number
through the routines.
This is fun!
#!/usr/bin/perl -w
use strict;
sub carls_version {
my $x = shift;
my $nbits = 32;
while(($x>>=1) != 0) {
--$nbits;
}
return 1<<(++$nbits);
}
sub lloyds_new_version {
use integer;
my $value = shift;
if ($value < 2) {
return (1);
}
$value--;
my $lastValue;
do {
$lastValue = $value;
} while (($value &= ($value - 1)) != 0);
return ($lastValue << 1);
}
sub toms_SmallestPowerOfTwoGE {
use integer;
my $a=sprintf("%o",(shift)-1);
return 1<<(3*length($a)+(-3,-2,-1,-1,0,0,0,0)[ord($a)-48]) ;
}
# This array is used within `variation_on_toms', below.
my @array = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3,2,1,1,0,0,0,0);
sub variation_on_toms {
use integer;
my $a=sprintf("%o",(shift)-1);
return 1<<(3*length($a)-$array[ord($a)]);
}
use Benchmark;
timethese (8, {
CARL => q{ my $i = (1 << 15) + 2;
while ($i-- > 0) {
my $spot = carls_version($i);
}
},
NEWLLOYD => q{ my $i = (1 << 15) + 2;
while ($i-- > 0) {
my $spot = lloyds_new_version($i);
}
},
TOM => q{ my $i = (1 << 15) + 2;
while ($i-- > 0) {
my $spot = toms_SmallestPowerOfTwoGE($i);
}
},
VARIATION => q{ my $i = (1 << 15) + 2;
while ($i-- > 0) {
my $spot = variation_on_toms($i);
}
},
});
__END__
Benchmark: timing 8 iterations of CARL, NEWLLOYD, TOM, VARIATION...
CARL: 17 secs (16.56 usr 0.00 sys = 16.56 cpu)
NEWLLOYD: 12 secs (12.25 usr 0.00 sys = 12.25 cpu)
TOM: 8 secs ( 8.22 usr 0.00 sys = 8.22 cpu)
VARIATION: 8 secs ( 7.90 usr 0.00 sys = 7.90 cpu)
--
Lloyd Zusman
ljz@asfast.com
------------------------------
Date: 18 Apr 1998 00:31:21 -0400
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: Fastest "smallest power of 2 >= N" in Perl?
Message-Id: <ltg1jbvjhi.fsf@asfast.com>
Lloyd Zusman <ljz@asfast.com> writes:
> [ ... ]
>
> Benchmark: timing 8 iterations of CARL, NEWLLOYD, TOM, VARIATION...
> CARL: 17 secs (16.56 usr 0.00 sys = 16.56 cpu)
> NEWLLOYD: 12 secs (12.25 usr 0.00 sys = 12.25 cpu)
> TOM: 8 secs ( 8.22 usr 0.00 sys = 8.22 cpu)
> VARIATION: 8 secs ( 7.90 usr 0.00 sys = 7.90 cpu)
OOPS! I forgot to put a "use integer" into the Perl-ized version of
Carl's routine. Here's the corrected version, followed by the updated
results. Carl's routine ran noticeably better, but the overall
rankings remained the same.
sub carls_version {
use integer;
my $x = shift;
my $nbits = 32;
while(($x>>=1) != 0) {
--$nbits;
}
return 1<<(++$nbits);
}
Benchmark: timing 8 iterations of CARL, NEWLLOYD, TOM, VARIATION...
CARL: 14 secs (13.79 usr 0.01 sys = 13.80 cpu)
NEWLLOYD: 12 secs (11.93 usr 0.00 sys = 11.93 cpu)
TOM: 8 secs ( 7.95 usr 0.00 sys = 7.95 cpu)
VARIATION: 8 secs ( 7.59 usr 0.00 sys = 7.59 cpu)
--
Lloyd Zusman
ljz@asfast.com
------------------------------
Date: Fri, 17 Apr 1998 22:12:56 -0700
From: Larry Rosler <lr@hpl.hp.com>
To: carl barron <cbarron3@ix.netcom.com>
Subject: Re: Fastest "smallest power of 2 >= N" in Perl?
Message-Id: <35383658.7C118BBE@hpl.hp.com>
carl barron wrote:
>
> Tom Rokicki <rokicki@cello.hpl.hp.com> wrote:
>
> > This is what I get:
> >
> > sub mySmallestPowerOfTwoGE {
> > use integer;
> > my $a=sprintf("%o",(shift)-1);
> > return 1<<(3*length($a)+(-3,-2,-1,-1,0,0,0,0)[ord($a)-48]) ;
> > }
>
> int power_2(unsigned long x)
> {
> int nbits = BITS_PER_LONG;
>
> while(x>>1) --nbits;
x >>= 1 (the original would run a very long time if x > 1 :-)
> return ++nbits;
return 1 << (BITS_PER_LONG - nbits);
> }
***
Better C version:
int mySmallestPowerOfTwoGE(unsigned long x)
{
int nbits = 0;
while (x >>= 1) ++nbits;
return 1 << nbits;
}
***
Benchmark adapted from Andre L.:
#!usr/local/bin/perl -w
use strict;
sub lloyds_smallestPowerOfTwoGE {
use integer;
my $value = shift;
if ($value < 2) {
return (1);
}
$value--;
my $lastValue;
do {
$lastValue = $value;
} while (($value &= ~(-$value)) != 0);
return ($lastValue << 1);
}
sub toms_SmallestPowerOfTwoGE {
use integer;
my $a=sprintf("%o",(shift)-1);
return 1<<(3*length($a)+(-3,-2,-1,-1,0,0,0,0)[ord($a)-48]) ;
}
sub carls_SmallestPowerOfTwoGE {
my $value = shift;
my $nbits = 0;
++$nbits while $value >>= 1;
return 1 << $nbits;
}
use Benchmark;
timethese (2**14, {
LLOYD => q{ my $spot = lloyds_smallestPowerOfTwoGE(31) },
TOM => q{ my $spot = toms_SmallestPowerOfTwoGE(31) },
CARL => q{ my $spot = carls_SmallestPowerOfTwoGE(31) },
LLOYD1 => q{ my $spot = lloyds_smallestPowerOfTwoGE(1 << 30) },
TOM1 => q{ my $spot = toms_SmallestPowerOfTwoGE(1 << 30) },
CARL1 => q{ my $spot = carls_SmallestPowerOfTwoGE(1 << 30) },
});
__END__
Benchmark: timing 16384 iterations of CARL, CARL1, LLOYD, LLOYD1, TOM,
TOM1...
CARL: 2 secs ( 1.30 usr 0.01 sys = 1.31 cpu)
CARL1: 4 secs ( 4.00 usr 0.00 sys = 4.00 cpu)
LLOYD: 2 secs ( 1.76 usr 0.01 sys = 1.77 cpu)
LLOYD1: 8 secs ( 7.21 usr 0.01 sys = 7.22 cpu)
TOM: 1 secs ( 1.20 usr 0.01 sys = 1.21 cpu)
TOM1: 0 secs ( 1.21 usr 0.00 sys = 1.21 cpu)
Conclusion: Tom's clever loopless algorithm is a clear winner.
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com
------------------------------
Date: Fri, 17 Apr 1998 22:49:54 -0700
From: Larry Rosler <lr@hpl.hp.com>
To: Lloyd Zusman <ljz@asfast.com>
Subject: Re: Fastest "smallest power of 2 >= N" in Perl?
Message-Id: <35383F02.12783EAC@hpl.hp.com>
Lloyd Zusman wrote:
>
> cbarron3@ix.netcom.com (carl barron) writes:
>
> > Tom Rokicki <rokicki@cello.hpl.hp.com> wrote:
> >
> > > This is what I get:
> > >
> > > sub mySmallestPowerOfTwoGE {
> > > use integer;
> > > my $a=sprintf("%o",(shift)-1);
> > > return 1<<(3*length($a)+(-3,-2,-1,-1,0,0,0,0)[ord($a)-48]) ;
> > > }
> >
> > int power_2(unsigned long x)
> > {
> > int nbits = BITS_PER_LONG;
> >
> >
> > while(x>>1) --nbits;
> > return ++nbits;
> > }
>
> Carl, your simple and elegent solution returns the number of bits, not
> the power of two itself. You'd have to do a `return 1<<(++nbits)'.
Did you notice that it "works" backwards? Largest input -> smallest
result.
...
> After looking at Tom's routine, I realized that I could streamline it
> slightly by using subtraction instead of addition and by getting rid
> of the "-48". This shaved a bit more time off of it. See below for
> the routine named `variation_on_toms'.
This looks like a case for the "discouraged" use of
local $[ = 48;
:-)
...
> This is fun!
That's what I said in the other thread (How to remove blanks?)!
...
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com
------------------------------
Date: 17 Apr 1998 19:50:51 -0700
From: richard1@leland.Stanford.EDU (Richard Pocklington)
Subject: function pointers
Message-Id: <6h94eb$1b8@epic11.Stanford.EDU>
Keywords: function pointers
Is there a perly way to accomplish what function pointers do?
in my rather sheltered programming experience this means ...
pass a variable into a subroutine that determines what function
that subroutine will call at a given spot.
thanks.
richard
------------------------------
Date: Sat, 18 Apr 1998 03:50:58 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: function pointers
Message-Id: <ebohlmanErLC0y.7Fz@netcom.com>
Richard Pocklington <richard1@leland.Stanford.EDU> wrote:
: Is there a perly way to accomplish what function pointers do?
Yep. References to subroutines. perldoc perlref for the details.
------------------------------
Date: Fri, 17 Apr 1998 20:59:59 -0700
From: Larry Rosler <lr@hpl.hp.com>
To: Zenin <zenin@archive.rhps.org>
Subject: Re: how to remove blanks?
Message-Id: <3538253F.D452456F@hpl.hp.com>
We may be about to lose everybody with this thread! However, a last (I
hope) shot...
Zenin wrote:
> Larry Rosler <lr@hpl.hp.com> wrote:
> >snip<
> : "These parentheses don't accomplish anything, except a small slowdown (see
> : below)."
> Even though not needed by the compiler, with the ?: at least they
> do not slow anything down as Benchmarks prove by going one way or
> the other (+ or - nano-seconds here...) depending on the exact
> location of my mouse xored with the exact about of coffee left in
> my cup. :-)
Not according to my Benchmarks (see below).
> Hmm, you have a bug in your code here.
Yes, but...
> Taking this into account, the numbers change back a lot. See below
> for a with/without test.
Clearly our mileage is varying -- I see a difference every time.
> >snip<
>
> If you run this a few times in a row you'll notice the Zenin
> with and without paren numbers will flip back and forth
> depending on the exact amount of coffee left in your cup and
> evaporation is taken into account when factoring in this number.
> Thus I stand by my claims that the parens do not have any effect
> what so ever on run time speed.
I agree -- they shouldn't, but they do! (see below).
> $ perl foo.pl
> Benchmark: timing 100000 iterations of EASIEST, EASIEST_REAL, FASTEST,
> FASTEST_REAL, TWO_PART, TWO_PART_REAL, ZENIN_NO_PAREN, ZENIN_NO_PAREN_REAL,
> ZENIN_PAREN, ZENIN_PAREN_REAL...
> EASIEST: 7 secs ( 6.73 usr 0.01 sys = 6.73 cpu)
> EASIEST_REAL: 9 secs ( 8.78 usr 0.00 sys = 8.78 cpu)
> FASTEST: 6 secs ( 5.69 usr 0.00 sys = 5.69 cpu)
> FASTEST_REAL: 9 secs ( 7.98 usr 0.00 sys = 7.98 cpu)
> TWO_PART: 2 secs ( 2.09 usr 0.00 sys = 2.09 cpu)
> TWO_PART_REAL: 4 secs ( 3.49 usr -0.01 sys = 3.48 cpu)
> ZENIN_NO_PAREN: 5 secs ( 3.22 usr 0.00 sys = 3.22 cpu)
> ZENIN_NO_PAREN_REAL: 7 secs ( 5.17 usr 0.00 sys = 5.17 cpu)
> ZENIN_PAREN: 4 secs ( 3.34 usr 0.00 sys = 3.34 cpu)
> ZENIN_PAREN_REAL: 6 secs ( 5.35 usr 0.01 sys = 5.36 cpu)
>
> Hmm, with TWO_PART's numbers now blowing away FASTEST, I think we have
> to change names, at least on my system. Hell, my version is now
> blowing away "FASTEST" on my machine! :-)
>
> I find it vary funny there is such a difference between your system
> and mine. What are you running your tests on? I'm running under 5.00404
> on FreeBSD 2.2.5-stable (p5/200). Hmm, maybe it's a CISC/RISC or
> bigending/littleending thing. :-P
See below (perl -v | head -n2, and uname -a)
>
> And of course, da code again :-)
>
> #!/usr/local/bin/perl -w
> use diagnostics;
> use strict;
> use Benchmark;
> use vars '$val';
> $val = ' ' x 12 . 'string' . ' ' x 11;
>
> timethese (100000, {
> EASIEST => q{
> $val =~ s/^\s*(.*?)\s*$/$1/;
> },
> TWO_PART => q{
> $val =~ s/^\s*//;
> $val =~ s/\s*$//;
> },
> ZENIN_NO_PAREN => q{
> $val =~ s/^\s*|\s*$//g;
> },
> ZENIN_PAREN => q{
> $val =~ s/(?:^\s*|\s*$)//g;
> },
> FASTEST => q{
> $val =~ s/^\s*(.*\S)\s*$/$1/;
> },
> EASIEST_REAL => q{
> $val = ' ' x 12 . 'string' . ' ' x 11;
> $val =~ s/^\s*(.*?)\s*$/$1/;
> },
> TWO_PART_REAL => q{
> $val = ' ' x 12 . 'string' . ' ' x 11;
> $val =~ s/^\s*//;
> $val =~ s/\s*$//;
> },
> ZENIN_NO_PAREN_REAL => q{
> $val = ' ' x 12 . 'string' . ' ' x 11;
> $val =~ s/^\s*|\s*$//g;
> },
> ZENIN_PAREN_REAL => q{
> $val = ' ' x 12 . 'string' . ' ' x 11;
> $val =~ s/(?:^\s*|\s*$)//g;
> },
> FASTEST_REAL => q{
> $val = ' ' x 12 . 'string' . ' ' x 11;
> $val =~ s/^\s*(.*\S)\s*$/$1/;
> },
> } );
>
> __END__
>
> --
> -Zenin
> zenin@archive.rhps.org
#!/usr/local/bin/perl -w
use diagnostics;
use strict;
use Benchmark;
timethese (100000, {
EASIEST => q{
my $val = ' ' x 12 . 'string' . ' ' x 11;
$val =~ s/^\s*(.*?)\s*$/$1/;
},
TWO_PART => q{
my $val = ' ' x 12 . 'string' . ' ' x 11;
$val =~ s/^\s*//;
$val =~ s/\s*$//;
},
ZENIN_NO_PAREN => q{
my $val = ' ' x 12 . 'string' . ' ' x 11;
$val =~ s/^\s*|\s*$//g;
},
ZENIN_PAREN => q{
my $val = ' ' x 12 . 'string' . ' ' x 11;
$val =~ s/(?:^\s*|\s*$)//g;
},
FASTEST => q{
my $val = ' ' x 12 . 'string' . ' ' x 11;
$val =~ s/^\s*(.*\S)\s*$/$1/;
},
} );
__END__
Benchmark: timing 100000 iterations of EASIEST, FASTEST, TWO_PART,
ZENIN_NO_PAREN, ZENIN_PAREN...
EASIEST: 10 secs ( 9.11 usr 0.00 sys = 9.11 cpu)
FASTEST: 8 secs ( 8.58 usr 0.00 sys = 8.58 cpu)
TWO_PART: 11 secs (10.24 usr 0.00 sys = 10.24 cpu)
ZENIN_NO_PAREN: 13 secs (11.73 usr 0.00 sys = 11.73 cpu)
ZENIN_PAREN: 13 secs (12.07 usr 0.00 sys = 12.07 cpu)
This is perl, version 5.002
HP-UX hpllr1 A.09.05 A 9000/735 20048338 12 two-user license
******************************************
Benchmark: timing 100000 iterations of EASIEST, FASTEST, TWO_PART,
ZENIN_NO_PAREN, ZENIN_PAREN...
EASIEST: 11 secs (10.59 usr 0.03 sys = 10.62 cpu)
FASTEST: 11 secs (10.54 usr 0.02 sys = 10.56 cpu)
TWO_PART: 9 secs ( 7.04 usr 0.03 sys = 7.07 cpu)
ZENIN_NO_PAREN: 12 secs ( 9.52 usr 0.04 sys = 9.56 cpu)
ZENIN_PAREN: 11 secs ( 9.75 usr 0.02 sys = 9.77 cpu)
This is perl, version 5.004_03
HP-UX rain B.10.20 B 9000/819 18641371 16-user license
******************************************
MY CONCLUSIONS (blare of trumpets):
1. I shall never again use perl 5.002 to Benchmark. The results can
differ markedly from perl 5.004. (Compare FASTEST/TWO_PART: 8.58/10.24
vs 10.54/7.04 !)
2. The FAQ is right -- TWO_PART is fastest with perl 5.004.
3. Both my machines are RISC/big-endian. The faster machine is still
slo.o.o.w!
4. I can reproduce about 3% difference from those pesky parentheses
that shouldn't matter.
5. I think we've learned all we can from this exercise, and it's time
to give it a rest. (Thousands of relieved sighs from around the
newsgroup.)
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com
------------------------------
Date: 18 Apr 1998 04:52:59 GMT
From: Zenin <zenin@archive.rhps.org>
Subject: Re: how to remove blanks?
Message-Id: <892875607.706980@thrush.omix.com>
Larry Rosler <lr@hpl.hp.com> wrote:
: We may be about to lose everybody with this thread! However, a last (I
: hope) shot...
<grin>
: > Even though not needed by the compiler, with the ?: at least they
: > do not slow anything down as Benchmarks prove by going one way or
: > the other (+ or - nano-seconds here...) depending on the exact
: > location of my mouse xored with the exact about of coffee left in
: > my cup. :-)
: Not according to my Benchmarks (see below).
Yes, our mileage is varying quite a bit it would seem. When I run
your benchmarks, I get the same information that mine where showing.
That is, at least when running 5.00404 under FreeBSD 2.2.5 on x86
hardware, that the two methods (with and without parens) flip flop
as to which is actually "faster" about 1/2 the time. This leads me
to believe that the parens don't make a difference and that any
minor difference shown in a Benchmark report is more do to the
tolerances of Benchmark then any real difference.
: Clearly our mileage is varying -- I see a difference every time.
Yep. :-)
: I agree -- they shouldn't, but they do! (see below).
Yep. And people wonder why I completely ignore benchmarks that
"prove", "IDE is as fast as SCSI" (it's not, no where close), "x86
hardware is as fast as RISC" (hehe, whatever), "NT out performs
Unix!" (sure, until the acid wares off).
There is no substitute for personal experience. It's something no
graph or chart will ever replace. What's the quote again, "In
theory, theory and practice are the same. In practice however, they
are not".
: 1. I shall never again use perl 5.002 to Benchmark. The results can
: differ markedly from perl 5.004. (Compare FASTEST/TWO_PART: 8.58/10.24
: vs 10.54/7.04 !)
Hehe. I'd recommend deleting 5.002 from your system actually, less
some misguided sole actually tries to use it. :-)
: 2. The FAQ is right -- TWO_PART is fastest with perl 5.004.
By a couple clock ticks. :-)
Hmm, maybe I should write an XSUB in asm to see if we can shave a
couple more off. <grin>
: 5. I think we've learned all we can from this exercise, and it's time
: to give it a rest. (Thousands of relieved sighs from around the
: newsgroup.)
Hehehe, but it's been fun, no? :-)
--
-Zenin
zenin@archive.rhps.org
------------------------------
Date: 18 Apr 1998 06:08:43 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: how to remove blanks?
Message-Id: <6h9g1b$g8$2@marina.cinenet.net>
Zenin (zenin@archive.rhps.org) wrote:
: Or somewhere in between, where we still only have one line of code,
: but it's nearly as fast as the two line version:
:
: $string =~ s/(?:^\s+|\s+$)//g;
That grouping paren set around the entire pattern seems pointless to me --
am I missing something?
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 18 Apr 98 06:18:55 GMT
From: mikeh@minivend.com (Mike Heins)
Subject: Re: how to remove blanks?
Message-Id: <353845cf.0@news.one.net>
Zenin <zenin@archive.rhps.org> wrote:
> Dan Boorstein <danboo@negia.net> wrote:
> : what do they accomplish? actually, how is what they accomplish useful
> : here? '$string =~ s/^\s+|\s+$//g' works just fine.
> Hmm, learn something new every day.
> : i'm not sure if this is a truism or not, but it seems to me that any
> : time you have:
> : /(?:foo)/
> : you can do away with the parens. you are merely being explicit in
> : declaring the default grouping. it's overkill.
> Comming from a shell background where sed at al (at least, older
> versions. Maybe it's different now...?) required that groups such
> as these be delimited explicitly. I carried this over to perl, if
> for no other reason then I don't think I've seen anyone else leave
> them off either.
> I still don't consider it overkill, just cleaner to read the exact
> intent. Speed is not affected at all (at least with ?: added so
> perl knows not to bother with storing it), as any tests will go one
> way or the other depending on the current phase of the moon:
> $ perl foo.pl
> Benchmark: timing 100000 iterations of WITH, WITHOUT...
> WITH: 4 secs ( 3.95 usr 0.01 sys = 3.95 cpu)
> WITHOUT: 3 secs ( 3.90 usr 0.00 sys = 3.90 cpu)
> $ perl foo.pl
> Benchmark: timing 100000 iterations of WITH, WITHOUT...
> WITH: 4 secs ( 3.87 usr 0.00 sys = 3.87 cpu)
> WITHOUT: 5 secs ( 3.84 usr 0.00 sys = 3.84 cpu)
> $ perl foo.pl
> Benchmark: timing 100000 iterations of WITH, WITHOUT...
> WITH: 5 secs ( 3.84 usr 0.00 sys = 3.84 cpu)
> WITHOUT: 4 secs ( 3.84 usr 0.00 sys = 3.84 cpu)
> Now, we are really, really talking about splitting hairs here. :-)
> The test code, for those that care:
I think we should care, for your test code does nothing except create a
subroutine reference thousands of times, and one has a syntax error. A
more meaningful comparision would be:
#!/usr/local/bin/perl
use Benchmark;
timethese 1_000_000, {
WITH => q{
$foo = ' foo ';
$foo =~ s/(?:^\s+|\+$)//g;
},
TWOOPS => q{
$foo = ' foo ';
$foo =~ s/^\s+//;
$foo =~ s/\s+$//g;
},
WITHOUT => q{
$foo = ' foo ';
$foo =~ s/^\s+|\s+$//g;
},
};
% perl foo.pl
Benchmark: timing 1000000 iterations of TWOOPS, WITH, WITHOUT...
TWOOPS: 7 secs ( 7.31 usr 0.00 sys = 7.31 cpu)
WITH: 18 secs (14.19 usr 0.02 sys = 14.21 cpu)
WITHOUT: 12 secs ( 9.77 usr 0.03 sys = 9.80 cpu)
% perl foo.pl
Benchmark: timing 1000000 iterations of TWOOPS, WITH, WITHOUT...
TWOOPS: 8 secs ( 7.28 usr 0.03 sys = 7.31 cpu)
WITH: 14 secs (14.14 usr 0.00 sys = 14.14 cpu)
WITHOUT: 9 secs ( 9.80 usr 0.00 sys = 9.80 cpu)
As has been exposed in the group many times before, the two operations
with a fixed beginning or ending string anchor blows away the alternation
operator. The parens do nothing but slow things down.
--
Mike Heins http://www.minivend.com/ ___
Internet Robotics |_ _|____
Just because something is 131 Willow Lane, Floor 2 | || _ \
obviously happening doesn't Oxford, OH 45056 | || |_) |
mean something obvious is <mikeh@minivend.com> |___| _ <
happening. --Larry Wall 513.523.7621 FAX 7501 |_| \_\
------------------------------
Date: Sat, 18 Apr 1998 01:14:21 -0500
From: phdss@writeme.comm
Subject: Perl Performace: CPU, and System Resource Usage.
Message-Id: <9SEO1IIelgmP092yn@netins.net>
Any faqs or articles discussing perl system performance? Speed tips
and other related matters?
TIA, Cheers: Brett
--
-- Brett Tabke (phdss at writeme.com)
-- hp: http://www.netins.net/showcase/phdss/
-- gfx: http://www.netins.net/showcase/phdss/busybee/busybee.htm
-- search engine: http://www.netins.net/showcase/phdss/howdy/
------------------------------
Date: Fri, 17 Apr 1998 20:01:14 -0700
From: snay <snay@primenet.com>
Subject: Re: Perl vs. Java
Message-Id: <35381779.B7C470F3@primenet.com>
Going along with the strand of standardization, let's face it... Java
doesn't work right 100%... it only works the way you want it to like 90%,
because of all the variations on the client side, the server on the other
hand conforms to a known standard that the perl programmers knows well
since he works with it constantly, and therefore it performs according to
it's standards, and effectively about 99.99999% of the time.
Jason Taylor wrote:
> Remember that comparing Java with Perl is like comparing Apples and
> Coffee :) Each has its place. I can't get Perl to scroll text across
> my screen warning my visitors that my page is still underconstruction,
> and I can't get down and Java doesn't do the CGI stuff that Perl can
> do. I've even had to employ Expect for somethings Perl won't do (at
> least as easily as I want).
>
> On Sat, 11 Oct 1997 22:11:33 -0500, Patrick O'Lone
> <polone@acc.mcrest.edu> wrote:
>
> >>
> >
> >Don't think that Java is better than Perl just yet! Consider the fact
> >that Java has not yet been STANDARDIZED. That is apparent in the Java
> >v1.0 to v1.1 upgrade in which almost everyone's older applets didn't
> >work without much headache of adjusting them. Perl can be an OOP
> >language, supporting objects, polymorphism, inheritance, multiple
> >inheritance, and overlays...
> >
> >Patrick O'Lone
> >polone@sanasys.com
> >polone@mcrest.edu
> >"The edge is everything..."
> >
> >
------------------------------
Date: 18 Apr 1998 04:36:48 GMT
From: Zenin <zenin@archive.rhps.org>
Subject: Re: Perl vs. Java
Message-Id: <892874636.433559@thrush.omix.com>
Jason Taylor <jtaylor@ala.net> wrote:
: Remember that comparing Java with Perl is like comparing Apples and
: Coffee :)
>snip<
Yep. As someone mentioned recently in a thread comparing FreeBSD
to Linux, you might as well as the question, "Which is tastier,
roasted dog or smoked cat?" on the rec.pets.cats.misc and
rec.pets.dogs.misc groups. The resulting threads would prove about
as useful as comparing Java to Perl, but at least it would be more
fun to watch. :-)
--
-Zenin
zenin@archive.rhps.org
------------------------------
Date: Sat, 18 Apr 1998 01:35:01 -0500
From: darren vollmer <inept@mail.anet-stl.com>
Subject: Perl, MySQL on my home PC
Message-Id: <35384995.4B411D1F@mail.anet-stl.com>
Ill try not to sound like a bonified moron:
I would like to install Perl (5.004) and MySQL on my laptop(win95) so
that I can build and debug scripts without connecting to a server. The
scripts, once finished will be uploaded to a Linux server running Perl
5.004 and MySQL.
What download of Perl should I get? Theres a quite a list of files. Do
I need to "build" the perl install with a c compiler? Where can I get a
compatible c compiler (free). I have a non compatable version boreland
compiler.
If someone out there could take the time to layout in newbie speak how
to correctly install and make perl, correctly install and make MySQL on
a win95 laptop/desktop it would be greatly appreciatted. The simplest
route to install that permits me to use the MySQL module is what I'm
looking for.
I realize that most , if not all, of this information is available on
the net, but the problem is: There is an overwhelming amount of it. I
have quite a bit of experience scripting in perl, but never setting it
up.
Thanks
Darren Vollmer
------------------------------
Date: Fri, 17 Apr 1998 19:56:27 -0700
From: snay <snay@primenet.com>
Subject: Retrieve HTML FORM POST info within CGI Perl Program
Message-Id: <3538165B.C66C74C2@primenet.com>
>From within my Perl CGI script I would like to access some HTML that is
generated by an HTML FORM with method Post, I know how to get just
straight HTML, and to get it into my Program via FORM method- GET, but
am clueless on this issue.
Essentially I am trying to extract Shipping rates from UPS's site, they
have utils setup to get the price on shipping, but they require the user
of my site to actually look at some stuff from UPS, and what I want to
do is have my Perl script just plug all the variables into a POST style
query statement, and transfer it to the CGI script over on the UPS site
and retrieve the HTML output of UPS's CGI, then use REGEX's and the like
to extract the shipping price for the users of my site. I can do
everything I need to but get the returned HTML into my CGI program, so
please help,
Shane
------------------------------
Date: Fri, 17 Apr 1998 20:20:30 -0700
From: snay <snay@primenet.com>
Subject: Re: Retrieve HTML FORM POST info within CGI Perl Program
Message-Id: <35381BFE.7A95D0F9@primenet.com>
Never mind, I spent 2hrs trying to figure it out.... well it turns out that
was 10 mins short of what I needed... Thanks for the responses I know you
guys would have sent my way
snay wrote:
> From within my Perl CGI script I would like to access some HTML that is
> generated by an HTML FORM with method Post, I know how to get just
> straight HTML, and to get it into my Program via FORM method- GET, but
> am clueless on this issue.
>
> Essentially I am trying to extract Shipping rates from UPS's site, they
> have utils setup to get the price on shipping, but they require the user
> of my site to actually look at some stuff from UPS, and what I want to
> do is have my Perl script just plug all the variables into a POST style
> query statement, and transfer it to the CGI script over on the UPS site
> and retrieve the HTML output of UPS's CGI, then use REGEX's and the like
> to extract the shipping price for the users of my site. I can do
> everything I need to but get the returned HTML into my CGI program, so
> please help,
> Shane
------------------------------
Date: Sat, 18 Apr 1998 02:05:03 -0400
From: Pat Kane <Pat_kane@compuserve.com>
Subject: Re: Retrieve HTML FORM POST info within CGI Perl Program
Message-Id: <3538428F.434D@compuserve.com>
snay,
The world wants to see how you solved this problem. Please share your
solution with us.
Pat
snay wrote:
>
> Never mind, I spent 2hrs trying to figure it out.... well it turns out that
> was 10 mins short of what I needed... Thanks for the responses I know you
> guys would have sent my way
>
> snay wrote:
>
> > From within my Perl CGI script I would like to access some HTML that is
> > generated by an HTML FORM with method Post, I know how to get just
> > straight HTML, and to get it into my Program via FORM method- GET, but
> > am clueless on this issue.
> >
> > Essentially I am trying to extract Shipping rates from UPS's site, they
> > have utils setup to get the price on shipping, but they require the user
> > of my site to actually look at some stuff from UPS, and what I want to
> > do is have my Perl script just plug all the variables into a POST style
> > query statement, and transfer it to the CGI script over on the UPS site
> > and retrieve the HTML output of UPS's CGI, then use REGEX's and the like
> > to extract the shipping price for the users of my site. I can do
> > everything I need to but get the returned HTML into my CGI program, so
> > please help,
> > Shane
------------------------------
Date: Fri, 17 Apr 1998 22:56:49 -0400
From: "Bob Gwynne" <gwynne@utkux.utk.edu>
Subject: Re: Server Side Include
Message-Id: <6h94sh$5of$1@gaia.ns.utk.edu>
See: ftp://ftp.dev.ecos.de/pub/perl/embperl/README
Bob Gwynne
Speech Comm
University of Tennessee
Jerry wrote in message <35367f97.3023569@news.nwinfo.net>...
>Is there any way to write one line in HTML that will run a PERL script
>that just prints part of a web page? I'm not interested in having the
>entire page CGI..
>
>E-Mail me if you have any insite.
>
>Thanx in advance.
------------------------------
Date: Fri, 17 Apr 1998 21:09:23 -0700
From: snay <snay@primenet.com>
Subject: Re: Snobby news group
Message-Id: <35382773.80CB790B@primenet.com>
I am essentially a perl newbie (well not really, but when I began reading this
newsgroup, I was). And I fully disagree with Database Coder, it is true you
must learn to find information for yourself. In essence that's what separates
computer people from computer users, and unless a person can make that essential
jump from being a computer user to a computer person, then they shouldn't even
be fiddling with a programming language. And I applaude those who told me to
read the FAQ, because I learned how to read the FAQ's, and the man pages,
because there the ones that really helped me out.
Let's face it if you can't read a man page or FAQ then it would take you
centuries to learn one single programming language, because you would have to
form all those individual questions like, how do I print to a file, and garbage
like that into sense able questions, and then wait for someone to post a
response. That whole process takes between 1hr to 2days, wereas looking through
the index of a book or the indexes in CPAN takes like 2min. I personally don't
even take the time to tell them to look at the FAQ... screw um' let them stay
Perl newbies the rest of there life, and let them choose a more simple career
like using the programs we write! However I will answer an intelligent
question, if I have an intelligent response... which since I am still learning
(i.e. still reading FAQ's and mans) isn't very often
Database Coder wrote:
> Why is this such a snobby unhelpful news group. I have posted in many other
> news groups and always recieved polite and helpful responses. This news
> group is the exception. The amount of time you people spend asking people if
> they read the FAQ or bought a good book on PERL could have been spent
> helping the person.
------------------------------
Date: Sat, 18 Apr 1998 04:39:28 +0100
From: Toby Heywood <toby@he-net.demon.co.uk>
Subject: uninitialized <STDIN> chunk 1. ????
Message-Id: <3538206F.879CAE26@he-net.demon.co.uk>
This is a multi-part message in MIME format.
--------------A5312335F9628386ECA16422
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi folks
If you have read any of my other messages to the comp.lang.perl.misc
group you will already know that I'm ne to perl, and have only just
started to learn the language. I'm using the book Learning Perl by
Randal L. Schwartz, to teach my self to program in perl.
anyway I'll get to the point. I have typed out one of the scripts, and
compiled it with the -w flag on, and I get a message which says:-
Use of uninitialized value at eercise2.6.pl line 6, <STDIN> chunk 1.
No I have read through the script about a dozen times now and I can't
find the problem. The one thing that has really stumped me is that the
error message is complaining about line 6 when
$guess = <STDIN>; is on line 5.
Can anyone shed some light on this?
Thank you for your help in advance.
--
Toby Heywood <toby@he-net.demon.co.uk>
Proprietor, Heywood Enterprises
----------------------------------------
Website - http://www.he-net.demon.co.uk/
----------------------------------------
--------------A5312335F9628386ECA16422
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Toby Heywood
Content-Disposition: attachment; filename="vcard.vcf"
begin: vcard
fn: Toby Heywood
n: Heywood;Toby
org: Heywood Enterprises
email;internet: toby@he-net.demon.co.uk
title: Proprietor
x-mozilla-cpt: ;0
x-mozilla-html: TRUE
version: 2.1
end: vcard
--------------A5312335F9628386ECA16422--
------------------------------
Date: 18 Apr 1998 06:19:42 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Wanna laugh? (My First cgi.pm Script)
Message-Id: <6h9glu$g8$3@marina.cinenet.net>
John Porter (jdporter@min.net) wrote:
: Craig Berry wrote:
: >
: > TANSTAAFL. FNORD. :)
:
: What do these stand for?
TANSTAAFL: "There ain't no such thing as a free lunch" (Originated by
Robert Heinlein in _The Moon is a Harsh Mistress_.) This little phrase
comes to mind frequently during the endless "lazy demanding newbies"
debates here and elsewhere on Usenet.
FNORD: Not an acronym. Probably. Depending on whom you believe. Read
Wilson and Shea's _Illuminatus_ for details. :)
: TINGRFCALIAS!
OK, same question to you!
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 2357
**************************************