[13889] in Perl-Users-Digest
Perl-Users Digest, Issue: 1299 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 8 14:43:03 1999
Date: Mon, 8 Nov 1999 11:42:53 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <942090173-v9-i1299@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 8 Nov 1999 Volume: 9 Number: 1299
Today's topics:
Re: How can I determine different "use" statements? <jtolley@bellatlantic.net>
Re: How can I determine different "use" statements? <rootbeer@redcat.com>
Re: How can I determine different "use" statements? <rootbeer@redcat.com>
Re: How can I determine different "use" statements? <aqumsieh@matrox.com>
Re: how can I display command results as they occur?? <noSpam@noSpam.com>
Re: how can I display command results as they occur?? <noSpam@noSpam.com>
Re: how can I display command results as they occur?? <rootbeer@redcat.com>
Re: how can I display command results as they occur?? <lr@hpl.hp.com>
Re: How can I set reg. expresion to anchor at the end o <cassell@mail.cor.epa.gov>
Re: How can I set reg. expresion to anchor at the end o (Charles DeRykus)
Re: How can I set reg. expresion to anchor at the end o (Charles DeRykus)
Re: How can I set reg. expresion to anchor at the end o lee.lindley@bigfoot.com
Re: How can I set reg. expresion to anchor at the end o (Abigail)
Re: How can I set reg. expresion to anchor at the end o lee.lindley@bigfoot.com
Re: How can I set reg. expresion to anchor at the end o <uri@sysarch.com>
Re: How can I set reg. expresion to anchor at the end o lee.lindley@bigfoot.com
Re: How can I set reg. expresion to anchor at the end o (Ilya Zakharevich)
Re: How can I set reg. expresion to anchor at the end o lee.lindley@bigfoot.com
Re: How can I set reg. expresion to anchor at the end o lee.lindley@bigfoot.com
Re: How can I store/print a variable containing a DISPL (Simon Cozens)
How can I write hex data to binary file? <rogdh@iname.com>
Re: How can I write hex data to binary file? <rick.delaney@home.com>
Re: How do I prevent wildcard expansion on the command <gellyfish@gellyfish.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 05 Nov 1999 14:34:59 GMT
From: James Tolley <jtolley@bellatlantic.net>
Subject: Re: How can I determine different "use" statements?
Message-Id: <3822EA90.37A7AC4@bellatlantic.net>
mozo wrote:
> Since the use statements are run on compile-time,
> How can I determine which module to be used in program?
> I do it this way:
>
> if(condition){
> use module1;
> use module2;
> }else{
> use module3;
> use moudle4;
> }
> But It seem need to have all 4 modules availble all the time,
> no matter what the condition is.
> What can I do?
I was faced with this a while back, and I solved it like this. I'm not
sure if there's a more elegant solution, but this worked for me.
if($pigs_fly) {
my $str = "use Module";
eval $str;
die "no mod: $@" if $@;
} else {
# ...etc
I used the variable $str above, instead of passing the "use ..." to eval
directly because I've seen some perls reject it that way at compile
time. It works fine on activeperl 522, though.
Of course, a guru-type (Tom Phoenix?) alleged recently that eval STRING
is evil, but I guess it's up to you whether or not you want to be
evil.;-)
(Anyone know why it's supposed to be evil, by the way?)
James
------------------------------
Date: Fri, 5 Nov 1999 12:11:07 -0800
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: How can I determine different "use" statements?
Message-Id: <Pine.GSO.4.10.9911051205570.29670-100000@user2.teleport.com>
On Fri, 5 Nov 1999, mozo wrote:
> Since the use statements are run on compile-time,
> How can I determine which module to be used in program?
Emulate the 'use' by re-writing it to use 'require'. See the docs for
'use' to see how. Don't forget to wrap that into a BEGIN block so that
the needed modules will still be loaded at compile time.
You should be aware that this may lead to parsing errors, if a prototyped
function is sometimes loaded and sometimes not loaded. To be safe, avoid
the prototype:
$result = &Mod::SomeFunc("foo");
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 5 Nov 1999 12:21:15 -0800
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: How can I determine different "use" statements?
Message-Id: <Pine.GSO.4.10.9911051211260.29670-100000@user2.teleport.com>
On Fri, 5 Nov 1999, James Tolley wrote:
> if($pigs_fly) {
> my $str = "use Module";
> eval $str;
> die "no mod: $@" if $@;
> } else {
> # ...etc
You'll usually want that to happen at compile time, so wrap that all in a
BEGIN block. Of course, then you have prototyping issues if an expected
subroutine is not defined.... :-P
> I used the variable $str above, instead of passing the "use ..." to eval
> directly because I've seen some perls reject it that way at compile
> time. It works fine on activeperl 522, though.
I'm not sure what you're saying there. But 'use' is a compile-time
directive. If you put it into an eval STRING, it'll be done at that
strings's compile time. Maybe you had a syntax error? This should work:
if ($pigs_fly) {
eval 'use Module;';
die if $@;
}
> Of course, a guru-type (Tom Phoenix?) alleged recently that eval
> STRING is evil, but I guess it's up to you whether or not you want to
> be evil.;-)
>
> (Anyone know why it's supposed to be evil, by the way?)
It's not _always_ evil, just as stealing candy from a baby isn't _always_
evil. But it's close.
When you eval a string, you are running code which isn't known until
runtime. This is against all principles of structured programming. It can
lead to programs which are difficult to debug. It can leak memory or even
(in very rare cases) crash your program. Avoid, avoid, avoid.
Fortunately, it's rare in modern Perl to need to use eval STRING. (Note
that eval BLOCK is not evil; it's a totally separate arrangement.) For
example, in this case, you can replace eval of 'use' with an ordinary
'require', along with a little extra code (see the docs for 'use').
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 5 Nov 1999 17:00:42 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: How can I determine different "use" statements?
Message-Id: <x3yaeossinp.fsf@tigre.matrox.com>
mozo <mozo@wahoo.com.tw> writes:
> Since the use statements are run on compile-time,
> How can I determine which module to be used in program?
> I do it this way:
>
> if(condition){
> use module1;
> use module2;
> }else{
> use module3;
> use moudle4;
> }
> ...
> ...
>
> But It seem need to have all 4 modules availble all the time,
> no matter what the condition is.
> What can I do?
s/use/require/;
perdoc -f require
--Ala
------------------------------
Date: Fri, 5 Nov 1999 08:49:39 -0700
From: "Bill Darbie" <noSpam@noSpam.com>
Subject: Re: how can I display command results as they occur??
Message-Id: <7vuubi$1qq$1@fcnews.fc.hp.com>
I tried that - but the make command is not getting executed
for some reason. I did the following to get things to work:
$file = "execute.tmp.$$";
system("$command 2>&1 | tee $file");
open(OUT, $file);
$out = "";
while (<OUT>)
{
$out .= $_;
}
close(OUT);
Any idea why the make was not being executed with your
solution?
Thanks
Bill
Makarand Kulkarni <makkulka@cisco.com> wrote in message news:38223ED1.559E335B@cisco.com...
> Bill Darbie wrote:
>
> > I have the following line of perl code:
> >
> > $out = `make 2>&1`;
> > print $out;
> >
> > This does a build of code for me and then prints the output.
> > The problem is that the build can take over an hour and I
> > want to see the results as they are happening. Right now
> > I see nothing for over an hour and then all the output comes
> > out at the end. How can I execute my make and see the
> > results unbuffered?
>
> $|++;
> # notice the Pipe in the second arg of open ()
> open ( OUT, 'make 2>&1 | ' ) or die "cannot start make \n " ;
> while ( <OUT>)
> {
> print $_;
> }
>
------------------------------
Date: Fri, 5 Nov 1999 09:02:01 -0700
From: "Bill Darbie" <noSpam@noSpam.com>
Subject: Re: how can I display command results as they occur??
Message-Id: <7vuv2n$21j$1@fcnews.fc.hp.com>
Thanks!
I really need to get the output from the make command so
I had to do something a little more complicated. Here is what
I ended up with:
$file = "execute.tmp.$$";
system("$command 2>&1 | tee $file");
open(OUT, $file);
$out = "";
while (<OUT>)
{
$out .= $_;
}
close(OUT);
Thanks again for the help
Bill
Abigail <abigail@delanet.com> wrote in message news:slrn8251kh.dk.abigail@alexandra.delanet.com...
> Bill Darbie (noSpam@noSpam.com) wrote on MMCCLVII September MCMXCIII in
> <URL:news:7vtbd4$4qe$1@fcnews.fc.hp.com>:
> // I have the following line of perl code:
> //
> // $out = `make 2>&1`;
> // print $out;
> //
> // This does a build of code for me and then prints the output.
> // The problem is that the build can take over an hour and I
> // want to see the results as they are happening. Right now
> // I see nothing for over an hour and then all the output comes
> // out at the end. How can I execute my make and see the
> // results unbuffered?
>
>
> By not doing doing things complicated:
>
> system "make";
>
>
> Abigail
> --
> perl -wle '$, = " "; print grep {(1 x $_) !~ /^(11+)\1+$/} 2 .. shift'
>
>
> -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
> http://www.newsfeeds.com The Largest Usenet Servers in the World!
> ------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Fri, 5 Nov 1999 08:45:25 -0800
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: how can I display command results as they occur??
Message-Id: <Pine.GSO.4.10.9911050843490.29670-100000@user2.teleport.com>
On Fri, 5 Nov 1999, Bill Darbie wrote:
> open(OUT, $file);
Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.
> $out = "";
> while (<OUT>)
> {
> $out .= $_;
> }
Likely faster, and certainly more perlish:
$out = join '', <OUT>;
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 5 Nov 1999 10:44:42 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: how can I display command results as they occur??
Message-Id: <MPG.128cc57150bd469298a1bf@nntp.hpl.hp.com>
In article <Pine.GSO.4.10.9911050843490.29670-100000@user2.teleport.com>
on Fri, 5 Nov 1999 08:45:25 -0800, Tom Phoenix <rootbeer@redcat.com>
says...
> On Fri, 5 Nov 1999, Bill Darbie wrote:
>
> > open(OUT, $file);
Though Bill meant OUT to refer to the output of the 'make' command, it
is nevertheless cruel and unusual to use it as the name of an input
filehandle.
> Even when your script is "just an example" (and perhaps especially in that
> case!) you should _always_ check the return value after opening a file.
>
> > $out = "";
> > while (<OUT>)
> > {
> > $out .= $_;
> > }
>
> Likely faster, and certainly more perlish:
>
> $out = join '', <OUT>;
Likely faster, and perhaps more perlish:
$out = do { local $/; <OUT> };
But you knew that.
> Cheers!
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 05 Nov 1999 13:51:32 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: How can I set reg. expresion to anchor at the end of a string?
Message-Id: <38235164.5D9FC6BB@mail.cor.epa.gov>
Neko wrote:
[snip]
> Perhaps this is a bug in my version of Perl (This is perl, version 5.005_02
> built for MSWin32-x86-object), but I changed the quantifier above to just
> four dots...
>
> my @pieces = $str =~ /(.{1,4})(?=(?:....)*$)/g;
>
> >print join(':', @pieces), "\n";
>
> ...and got different results:
>
> 1212:3412:3412:34 # .{4}
> 12:1234:1234:1234 # ....
>
> I get the expected the latter result for both with an earlier Perl (This is
> perl, version 5.004_04 built for i586-linux). How is it with newer Perls?
I have:
This is perl, version 5.005_03 built for MSWin32-x86-object
(with 1 registered patch, see perl -V for more detail)
and:
#!perl -w
use strict;
my $str = '12123412341234';
my @pieces;
@pieces = $str =~ /(.{1,4})(?=(?:.{4})*$)/g;
print join(':', @pieces), "\n";
@pieces = $str =~ /(.{1,4})(?=(?:....)*$)/g;
print join(':', @pieces), "\n";
yields:
12:1234:1234:1234
12:1234:1234:1234
So it looks like a bug in that build, at least.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Sat, 6 Nov 1999 01:26:29 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: How can I set reg. expresion to anchor at the end of a string?
Message-Id: <FKr5C5.DAu@news.boeing.com>
In article <7vsbsr$jcu$1@rguxd.viasystems.com>,
<lee.lindley@bigfoot.com> wrote:
>
>my $f = length($_) % 4;
>my @x = /^.{$f}|.{4}/g;
>
Hm,
perl -e '$_="abcd";$f=0;@x=/^.{$f}|.{4}/g;print "\@x=@x\n"'
@x=
perl -e '$_="abcde";$f=1;@x=/^.{$f}|.{4}/g;print "\@x=@x\n"'
@x=a bcde
perl -v
This is perl, version 5.005_03 built for sun4-solaris-thread
--
Charles DeRykus
------------------------------
Date: Sat, 6 Nov 1999 02:27:02 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: How can I set reg. expresion to anchor at the end of a string?
Message-Id: <FKr853.F0o@news.boeing.com>
In article <YAohOLPr=b7dzeqptlJB3qNWgLO2@4ax.com>,
Neko <tgy@chocobo.org> wrote:
>
>
>
interestingly. Abigail's solution is faster for "reasonably"
sized strings; with larger strings, building a monolithic
regex string appears to consistently have the edge.
use Benchmark;
for (1, 4, 8, 16, 32) {
my $str = '1234567890' x $_;
print "N=", length $str, "\n";
timethese 20000, {
Neko => sub { my @a = $str =~ /(?!^)....|.+?(?=(?:....)*\z)/gs; },
Abigail => sub { my @a = ((length ($str) % 4 ? substr $str => 0,
length ($str) % 4 : ()),
(substr $str => length ($str) % 4) =~ /..../gs);
},
mono_re => sub { my $re = "(" . ("." x (length($str) % 4)) . ")" .
("(....)" x (length($str) / 4));
my @a = $str =~ /$regex/
},
};
}
__END__
N=10
Benchmark: timing 20000 iterations of Abigail, Neko, mono_re...
Abigail: 3 wallclock secs ( 2.01 usr + 0.01 sys = 2.02 CPU)
Neko: 3 wallclock secs ( 2.12 usr + 0.00 sys = 2.12 CPU)
mono_re: 3 wallclock secs ( 2.26 usr + 0.01 sys = 2.27 CPU
N=40
Benchmark: timing 20000 iterations of Abigail, Neko, mono_re...
Abigail: 4 wallclock secs ( 5.39 usr + 0.00 sys = 5.39 CPU)
Neko: 5 wallclock secs ( 6.32 usr + 0.00 sys = 6.32 CPU)
mono_re: 5 wallclock secs ( 5.77 usr + 0.01 sys = 5.78 CPU)
N=80
Benchmark: timing 20000 iterations of Abigail, Neko, mono_re...
Abigail: 10 wallclock secs ( 9.92 usr + 0.00 sys = 9.92 CPU)
Neko: 11 wallclock secs (12.05 usr + 0.00 sys = 12.05 CPU)
mono_re: 11 wallclock secs (10.19 usr + 0.01 sys = 10.20 CPU)
N=160
Benchmark: timing 20000 iterations of Abigail, Neko, mono_re...
Abigail: 20 wallclock secs (19.61 usr + 0.01 sys = 19.62 CPU)
Neko: 24 wallclock secs (23.57 usr + 0.00 sys = 23.57 CPU)
mono_re: 20 wallclock secs (19.12 usr + 0.01 sys = 19.13 CPU)
N=320
Benchmark: timing 20000 iterations of Abigail, Neko, mono_re...
Abigail: 39 wallclock secs (38.09 usr + 0.01 sys = 38.10 CPU)
Neko: 47 wallclock secs (46.43 usr + 0.02 sys = 46.45 CPU)
mono_re: 37 wallclock secs (36.61 usr + 0.01 sys = 36.62 CPU)
--
Charles DeRykus
------------------------------
Date: 6 Nov 1999 03:17:07 GMT
From: lee.lindley@bigfoot.com
Subject: Re: How can I set reg. expresion to anchor at the end of a string?
Message-Id: <8006jj$2ai$1@rguxd.viasystems.com>
Charles DeRykus <ced@bcstec.ca.boeing.com> wrote:
:>In article <7vsbsr$jcu$1@rguxd.viasystems.com>,
:> <lee.lindley@bigfoot.com> wrote:
:>>
:>>my $f = length($_) % 4;
:>>my @x = /^.{$f}|.{4}/g;
:>>
:>Hm,
:>perl -e '$_="abcd";$f=0;@x=/^.{$f}|.{4}/g;print "\@x=@x\n"'
:>@x=
Hm yourself,
perl -e '$_="abcdefgh";$f=0;@x=/^.{$f}|.{4}/g;print "\@x=@x\n"'
@x= bcde
---^
Oh Shit. I seem to have overlooked an edge case, something
I was accused of in an earlier thread where I pleaded for
my own sainthood. I suppose I am just a reckless sinner after
all. :-)
:>perl -e '$_="abcde";$f=1;@x=/^.{$f}|.{4}/g;print "\@x=@x\n"'
:>@x=a bcde
:>perl -v
:>This is perl, version 5.005_03 built for sun4-solaris-thread
Not a bug in perl, but not obvious either. First, '^.{0}' matches.
It puts the empty string into the array entry $x[0]. Then following
the rule that pos() must be advanced after a successful 0 width
match, the next match is attempted after the first character is
skipped.
I know this problem well. It bit me for 2 nights running when
I was working on my context grep contest entry. I finally enlisted
Ilya's help. He didn't see it right away either. We both eventually
found the bug (bug in my coding, not in perl) independently, but not
until after Ilya had added additional debugging information to
the "use re 'debug'" pragma for future versions of perl. I consider
that a very good thing now that I have made the very same
mistake twice!
Redemption.
$_ = "abcd"; # works with "abcdefgh" too.
my $f = length($_) % 4 || 4;
my @x = /^.{$f}|.{4}/g;
print "@x\n";
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: 5 Nov 1999 21:58:24 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: How can I set reg. expresion to anchor at the end of a string?
Message-Id: <slrn827a1v.dk.abigail@alexandra.delanet.com>
Charles DeRykus (ced@bcstec.ca.boeing.com) wrote on MMCCLVIII September
MCMXCIII in <URL:news:FKr853.F0o@news.boeing.com>:
-- In article <YAohOLPr=b7dzeqptlJB3qNWgLO2@4ax.com>,
-- Neko <tgy@chocobo.org> wrote:
-- >
-- >
-- >
--
-- interestingly. Abigail's solution is faster for "reasonably"
-- sized strings; with larger strings, building a monolithic
-- regex string appears to consistently have the edge.
--
-- use Benchmark;
-- for (1, 4, 8, 16, 32) {
-- my $str = '1234567890' x $_;
-- print "N=", length $str, "\n";
-- timethese 20000, {
-- Neko => sub { my @a = $str =~ /(?!^)....|.+?(?=(?:....)*\z)/gs; },
-- Abigail => sub { my @a = ((length ($str) % 4 ? substr $str => 0,
-- length ($str) % 4 : ()),
-- (substr $str => length ($str) % 4) =~ /..../gs);
-- },
-- mono_re => sub { my $re = "(" . ("." x (length($str) % 4)) . ")" .
-- ("(....)" x (length($str) / 4));
-- my @a = $str =~ /$regex/
-- },
-- };
-- }
-- __END__
Well, had you used 'use strict', you would have noticed that /$regex/
isn't quite working if you build the regex in $re....
If we fix that, we get:
N=10
Benchmark: timing 20000 iterations of Abigail, Neko, mono_re...
Abigail: 1 wallclock secs ( 0.86 usr + 0.00 sys = 0.86 CPU)
Neko: 1 wallclock secs ( 1.02 usr + 0.02 sys = 1.04 CPU)
mono_re: 2 wallclock secs ( 1.14 usr + 0.00 sys = 1.14 CPU)
N=40
Benchmark: timing 20000 iterations of Abigail, Neko, mono_re...
Abigail: 2 wallclock secs ( 1.49 usr + 0.00 sys = 1.49 CPU)
Neko: 3 wallclock secs ( 2.47 usr + 0.00 sys = 2.47 CPU)
mono_re: 2 wallclock secs ( 1.80 usr + 0.00 sys = 1.80 CPU)
N=80
Benchmark: timing 20000 iterations of Abigail, Neko, mono_re...
Abigail: 3 wallclock secs ( 2.42 usr + 0.00 sys = 2.42 CPU)
Neko: 4 wallclock secs ( 4.28 usr + 0.00 sys = 4.28 CPU)
mono_re: 3 wallclock secs ( 2.73 usr + 0.00 sys = 2.73 CPU)
N=160
Benchmark: timing 20000 iterations of Abigail, Neko, mono_re...
Abigail: 4 wallclock secs ( 4.30 usr + 0.00 sys = 4.30 CPU)
Neko: 9 wallclock secs ( 7.89 usr + 0.00 sys = 7.89 CPU)
mono_re: 5 wallclock secs ( 4.54 usr + 0.00 sys = 4.54 CPU)
N=320
Benchmark: timing 20000 iterations of Abigail, Neko, mono_re...
Abigail: 9 wallclock secs ( 7.90 usr + 0.00 sys = 7.90 CPU)
Neko: 17 wallclock secs (15.15 usr + 0.00 sys = 15.15 CPU)
mono_re: 9 wallclock secs ( 8.08 usr + 0.02 sys = 8.10 CPU)
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
.qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 6 Nov 1999 05:08:58 GMT
From: lee.lindley@bigfoot.com
Subject: Re: How can I set reg. expresion to anchor at the end of a string?
Message-Id: <800d5a$45f$1@rguxd.viasystems.com>
Charles DeRykus <ced@bcstec.ca.boeing.com> wrote:
:>In article <YAohOLPr=b7dzeqptlJB3qNWgLO2@4ax.com>,
:>Neko <tgy@chocobo.org> wrote:
:>>
:>>
:>>
:>
:>interestingly. Abigail's solution is faster for "reasonably"
:>sized strings; with larger strings, building a monolithic
:>regex string appears to consistently have the edge.
My own results on an ultrasparc showed the mono_re (Just call it the
Charles re since you were the only one "out there" enough to think it
would be better :) was actually faster in all of the string lengths in
your benchmarks.
I held out false hope that my own (corrected) entry would fair well,
but it only beat out Niko. :-< I still like it for elegance
though.
Every time that I see these kinds of results I am reminded of how
counterintuitive it seems. Alternation is so much more expensive
than I want it to be when the left side of the 'or' fails frequently.
On the other hand this benchmark shows that the more you let happen
in the re engine on a single pass and the less in Perl code the
better. In this case building a single re that you "know" will match
the entire string on the first pass is pretty clever. Of course if
you bump up your streng length you can run into the limit on the
total size of a re, but we have already carried this problem to silly
extremes.
I suppose I will have to break down and read the Mastering Regular
Expressions book, but I've been holding out hoping that Friedel (sp?)
would do another edition.
PS
Multiples of 4 on your string lengths for testing could be
misleading. The results look slightly different otherwise
in my limited testing; the Neko solution comes out better.
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: 06 Nov 1999 00:32:39 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: How can I set reg. expresion to anchor at the end of a string?
Message-Id: <x7904c422w.fsf@home.sysarch.com>
>>>>> "ll" == lee lindley <lee.lindley@bigfoot.com> writes:
ll> I suppose I will have to break down and read the Mastering Regular
ll> Expressions book, but I've been holding out hoping that Friedel (sp?)
ll> would do another edition.
even though it is outdated regarding perl's newer regex features i think
it is still very educational on regexes in general and it is still
useful for most of perl's regex stuff (this thread is likely not
covered in it). the word i get is that he is way too busy at yahoo to do
it. o'reilly very much wants a new edition and is trying to get an
author to take it on.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 6 Nov 1999 05:29:23 GMT
From: lee.lindley@bigfoot.com
Subject: Re: How can I set reg. expresion to anchor at the end of a string?
Message-Id: <800ebj$45f$3@rguxd.viasystems.com>
Abigail <abigail@delanet.com> wrote:
:>Well, had you used 'use strict', you would have noticed that /$regex/
:>isn't quite working if you build the regex in $re....
Doh!
I already postulated a reason for it! Time to go to bed.
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: 6 Nov 1999 06:47:46 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: How can I set reg. expresion to anchor at the end of a string?
Message-Id: <800iui$o90$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to
<lee.lindley@bigfoot.com>],
who wrote in article <800d5a$45f$1@rguxd.viasystems.com>:
> On the other hand this benchmark shows that the more you let happen
> in the re engine on a single pass and the less in Perl code the
> better. In this case building a single re that you "know" will match
> the entire string on the first pass is pretty clever. Of course if
> you bump up your streng length you can run into the limit on the
> total size of a re
What limit on the total size of a re?
Ilya
------------------------------
Date: 6 Nov 1999 14:56:17 GMT
From: lee.lindley@bigfoot.com
Subject: Re: How can I set reg. expresion to anchor at the end of a string?
Message-Id: <801fih$fak$2@rguxd.viasystems.com>
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
:>[A complimentary Cc of this posting was sent to
:><lee.lindley@bigfoot.com>],
:>who wrote in article <800d5a$45f$1@rguxd.viasystems.com>:
:>> On the other hand this benchmark shows that the more you let happen
:>> in the re engine on a single pass and the less in Perl code the
:>> better. In this case building a single re that you "know" will match
:>> the entire string on the first pass is pretty clever. Of course if
:>> you bump up your streng length you can run into the limit on the
:>> total size of a re
:>What limit on the total size of a re?
The one where you run out of stack space. But I suppose it
doesn't apply here. No +, * or {x,y}.
This has not been a good week for me on "being right."
I'm going to have to come up with a new sig. :-)
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: 7 Nov 1999 04:07:21 GMT
From: lee.lindley@bigfoot.com
Subject: Re: How can I set reg. expresion to anchor at the end of a string?
Message-Id: <802ttp$s2n$1@rguxd.viasystems.com>
lee.lindley@bigfoot.com wrote:
:>$_ = "abcd"; # works with "abcdefgh" too.
:>my $f = length($_) % 4 || 4;
:>my @x = /^.{$f}|.{4}/g;
:>print "@x\n";
Still not any faster in the benchmark, much to my chagrin, but yet
another way:
$_ = "abcd1234";
my $f = length($_) % 4 || 4;
/(^.{$f})/g; # //g not required for \G in future
my @x = ("$1", /\G.{4}/g); # Please question the quotes. Double Dare.
print "@x\n";
Abigail's use of substr to separate the first part from the
rest seems to be the winner until the string gets silly long.
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: 7 Nov 1999 07:48:12 GMT
From: simon@othersideofthe.earth.li (Simon Cozens)
Subject: Re: How can I store/print a variable containing a DISPLAY IP address?
Message-Id: <slrn82abls.o1i.simon@othersideofthe.earth.li>
David Cassell (comp.lang.perl.misc):
> Even with the PSI::ESP module, I can't help
>you without some indication of what's going wrong for you.
Oh, They finally released it?
It doesn't seem to be on CPAN. Guess I'll just have to work out where
to find it.
--
Behind every great computer sits a skinny little geek.
------------------------------
Date: Fri, 05 Nov 1999 19:34:10 +0000
From: rogdh <rogdh@iname.com>
Subject: How can I write hex data to binary file?
Message-Id: <HTAjOMiw0CP=9=uu=VeQFu=go7bA@4ax.com>
I want to create a binary file that contains only 2 bytes.
I want to be able to write any hex number between
0x0000 and 0xFFFF. (0 - 65535)
I tried pack, binmode, hex, syswrite...
I just can't get the right combination.
Any help appreciated.
roger
rogdh@iname.com
------------------------------
Date: Sat, 06 Nov 1999 05:11:42 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: How can I write hex data to binary file?
Message-Id: <3823B8A2.D8F05C60@home.com>
[posted & mailed]
rogdh wrote:
>
> I want to create a binary file that contains only 2 bytes.
> I want to be able to write any hex number between
> 0x0000 and 0xFFFF. (0 - 65535)
>
> I tried pack, binmode, hex, syswrite...
pack good, binmode good, hex nah, syswrite sure
> I just can't get the right combination.
What exactly did you try?
> Any help appreciated.
perl -we 'print pack n => int rand 0xffff + 1'
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: 6 Nov 1999 15:11:33 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: How do I prevent wildcard expansion on the command line?
Message-Id: <801gf5$arv$1@gellyfish.btinternet.com>
On Wed, 3 Nov 1999 06:40:54 -0800 Peter Steele wrote:
> I'm getting back into Perl after a ten year absence. I probably used to know
> the answer to this but it escapes me right now. I'm writing a simple perl
> app under Windows NT that can optionally be executed as
>
> myapp /?
>
> which is more or less standard for DOS commands to display a brief help
> message about the command. When I do this though the /? is being treating as
> a file reference with wildcards so when I check $ARGV[0] it isn't "/?". How
> do I prevent this from happening?
>
This doesnt happen on recent versions of Perl for Win32 (I am thinking of
ActivePerl here) which have reverted to the behaviour of the Unix versions
which leave file spec expansion to the shell that Perl is being executed
by - you might want to upgrade your Perl.
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 1299
**************************************