[12770] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 180 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 18 06:07:28 1999

Date: Sun, 18 Jul 1999 03:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 18 Jul 1999     Volume: 9 Number: 180

Today's topics:
    Re: ActiveState Perl -w Problem? (James M. Mastros)
    Re: Anybody know how to to this? (James M. Mastros)
        array reference through a function problem maxime69@my-deja.com
    Re: array reference through a function problem (Randal L. Schwartz)
    Re: Closing Web Browser Connection on Lengthy Processes (Abigail)
    Re: general--stupid question from a beginner <cs2400@hotmail.com>
    Re: general--stupid question from a beginner (Dave Cross)
    Re: How can I do a case insensitive search? (Larry Rosler)
    Re: newbie needs help! <uri@sysarch.com>
    Re: newbie needs help! (Larry Rosler)
    Re: newbie needs help! <uri@sysarch.com>
    Re: Old database is erased when I add new information (Neko)
        Perl, Apche, Win32 and Crypt Question <akirby@cableregina.com>
    Re: pure perl solution for Blowfish, DES or IDEA? <ehpoole@ingress.com>
    Re: Question: optimized method for finding the maximum  (Larry Rosler)
    Re: Regular expression question (Problems with parsing  (Abigail)
    Re: split() (Abigail)
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 18 Jul 1999 09:16:44 GMT
From: theorb@hildy.dhis.org (James M. Mastros)
Subject: Re: ActiveState Perl -w Problem?
Message-Id: <slrn7p36ia.9kk.theorb@hildy.dhis.org>

In article <378B7C52.6ECAFBA8@patriot.net>, Marquis de Carvdawg wrote:
>try
>
>#! c:\perl\bin\perl.exe -w
>
>> Can't exec -w at ex2-2.pl line 1.

In specific, your shebang line has to include the string "perl" in it
somewhere.  "#!/usr/bin/perl -w" will work just find on a win32 system (I
oft use it, half out of habit and half because I'll just upload it to a Real
OS box anyway).  If perl finds 'perl', it will process the args on the
shebang.  If perl dosn't find 'perl', it will assume that it isn't Perl.
(Don't you love it when non-pronouncable differences are highly meaningfull
in English?  It's kinda trippy.)

	-=- James
-- 
length(English($perl)) > length(Perl($english)) is often defined.


------------------------------

Date: Sun, 18 Jul 1999 09:34:46 GMT
From: theorb@hildy.dhis.org (James M. Mastros)
Subject: Re: Anybody know how to to this?
Message-Id: <slrn7p37k3.9kk.theorb@hildy.dhis.org>

In article <slrn7oq8u5.c9j.abigail@alexandra.delanet.com>, Abigail wrote:
>%% I want to write a cgi for apache webserver on Digital Ux using perl.
>
>You want to write an interface? Or do you plan to write a program that
>uses the CGI? Let's assume the latter....

CGI is an interface, a CGI is a program designed to be called using that
interface.  (This is somwhat less convoluted then Perl being a language and
perl being a program.  Normaly.)

(If you're going to flame, flame correctly.  (Humor has no such requirement,
IMHO.))

>perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
>         / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
>         % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
>         BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'
My perl gives "Illegal division by zero at -e line 4.".  Bug in your
signature, or my perl (5.005_57 on Linux).

Oh, and BTW, what the original author wanted could be...
print "Content-type: text/plain\n\n$_"; #If that's _ALL_ you want to output
or
print "Content-type: text/html\n\n";
s|&|&amp;|g;
s|<|&lt;|g;
s| |&nbsp;|g;
s|\n|\n<br>|g;
print;

(Both assuming the varible in question is $_.)
Most people missed the escaping of '&' and '<'.  The nbsp'ing you may or may
not want to do, depending on just what you require -- it will keep formating
better, but produce _really_ ugly code.  Only replaceing ' ' with &nbsp;
would be nicer, but require me to acatualy think -- and I don't think is as
easy as a simple regex (but sombody will probably corectly; regexes are
probably the most powerful programing language embeded within a programing
language by specification).

	-=- James Mastros
-- 
If you don't have enough content to neturlize your acidicy, you might melt
some fibre, and that would lower available bandwidth, so we'd have to kill
you.  Muhahaha!


------------------------------

Date: Sun, 18 Jul 1999 08:27:05 GMT
From: maxime69@my-deja.com
Subject: array reference through a function problem
Message-Id: <7ms34m$uqj$1@nnrp1.deja.com>

I would like to know why #1 runs correctly, while #2 don't print
anything.

package main;

my @array;

sub foo() {
	my $ArrayRef = @_;
	$ArrayRef->[0] = "pippo";
	$ArrayRef->[1] = "pluto";
	print $ArrayRef->[0], " ", $ArrayRef->[1], "\n"; #1
}

&foo(\@array);
print $array->[0], " ", $array->[1], "\n"; #2

Thanx in advance
Max


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


------------------------------

Date: 18 Jul 1999 02:10:15 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: array reference through a function problem
Message-Id: <m1vhbi7288.fsf@halfdome.holdit.com>

>>>>> "maxime69" == maxime69  <maxime69@my-deja.com> writes:

maxime69> &foo(\@array);
maxime69> print $array->[0], " ", $array->[1], "\n"; #2

Perhaps because @array and $array have nothing to do with each other?
By the way, "use strict" would have caught this.

print "Just another Perl hacker,"

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


------------------------------

Date: 18 Jul 1999 01:35:16 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Closing Web Browser Connection on Lengthy Processes
Message-Id: <slrn7p2tc3.c9j.abigail@alexandra.delanet.com>

bane_dewitt@my-deja.com (bane_dewitt@my-deja.com) wrote on MMCXLVII
September MCMXCIII in <URL:news:7mr5g4$m4s$1@nnrp1.deja.com>:
 .. 
 .. No takers? I'm not asking to be spoon fed - I'm ready to do more work
 .. to learn the answer to this, I just don't know where to turn to next.
 .. Some FAQs come close to answering it, but the code that I try doesn't
 .. do what I think it's supposed to do. It looks like one just closes
 .. STDOUT and forks a new process, but that doesn't close the browser
 .. connection. Hm.
 .. 
 .. If it's off topic, would someone please slap me with a big fish and
 .. tell me where to ask?

*SLAP WITH A BIG FISH*

Your program has no connection with the browser.

Your server has. Your server is on the www.


That should be enough information to figure out where to ask.




Abigail


-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


  -----------== 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: Sun, 18 Jul 1999 00:04:20 -0400
From: "c.s." <cs2400@hotmail.com>
Subject: Re: general--stupid question from a beginner
Message-Id: <932270745.353.99@news.remarQ.com>


CLTCEvans wrote in message
<19990717234140.12039.00001038@ng-fd1.aol.com>...
>i am running perl scripts under unix.  do they have to be in a
cgi-bin?

This depends on you server's config....  Some servers will let you exec
a .cgi file form anywhere.  Try and see what works.....

>also, does my perl interpreter/compiler have to be anywhere special?

Nope, but you need to know the path to the Perl program.  Often it is
somthing like /usr/bin/perl or /usr/bin/perl5.  (Tip: make sure the
version of perl you are using is the latest... )

>finally, do i have to have a special line of codein the perl scripts
to tell
>where to look for the interpreter?

 yep, you need to put the path to the copy of perl you want at the top
of your cgi....  Like so:
#!/usr/bin/perl

Where  /usr/bin/perl is the right path.





------------------------------

Date: Sun, 18 Jul 1999 08:08:33 GMT
From: dave@dave.org.uk (Dave Cross)
Subject: Re: general--stupid question from a beginner
Message-Id: <37918a74.784393@news.demon.co.uk>

On 18 Jul 1999 03:41:40 GMT, cltcevans@aol.com (CLTCEvans) wrote:

>i am running perl scripts under unix.  do they have to be in a cgi-bin?

Most Perl scripts have nothing to do with CGI. Therefore most scripts
don't need t obe in cgi-bin. For the small minority scripts that are
to be run in rsponse to CGI requests, where they have to be depnds on
the configuration of the web server. One very common configuration is
that files in cgi-bin or files that have the extension.cgi are
considered executable.

>also, does my perl interpreter/compiler have to be anywhere special?

Your Perl interpreter can be anywhere that is accessable when you are
trying to run the script.

>finally, do i have to have a special line of codein the perl scripts to tell
>where to look for the interpreter?

The first line of a script should contain the path to your Perl
interpreter like this:

#!/path/.to/perl -w

The '-w' is also very important. It will find bugs in your code that
you didn't know existed.

hth,

Dave...

--
Dave Cross <dave@dave.org.uk>
<http://www.dave.org.uk>


------------------------------

Date: Sat, 17 Jul 1999 22:47:12 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How can I do a case insensitive search?
Message-Id: <MPG.11fb0a40db15469c989cf2@nntp.hpl.hp.com>

In article <7mq455$vhb$1@news3.infoave.net> on Sat, 17 Jul 1999 09:32:02 

-0500, Jim <syt@email*> says...
+ if ($string =~ /$searchstring/I) {
+   print "Found!\n";
+ }
+ 
+ capital "i" is for case insensitive

It would have take you perhaps one minute to test this assertion before 
posting it.  You might also have looked in the documentation, in which 
case you could have aimed the questioner correctly.  But no...

+ --

If you add a magic invisible space after those two dashes, then 
competent newsreaders such as mine won't repost your signature, which in 

any case violates Usenet conventions by being 8 lines long instead of 4 
or fewer.

+ -Jim- syt.at.email.dot.com
+ ----------------------------------
+ -I don't suffer from insanity, I enjoy every minute of it.
+ -So what if I'm paranoid? It doesn't hurt anybody
+ and makes life interesting for me.
+ ----------------------------------
+ - Get Paid For Staying Online -
+ http://www.alladvantage.com/refhome.asp?refid=ANT424
+ 
+ 
+ [L] Vicious! <baal@c2i.net> wrote in message
+ news:Ab0k3.709$_L6.50105@juliett.dax.net...
+ I've just programmed a searchengine, and need some help. How can I do
+ a case insensitive search? Now I use:
+ 
+ #simplified
+ if ($string =~ /$searchstring/) {
+   print "Found!\n";
+ }

This is what you were responding too.  Why isn't it ahead of your 
response as in normal human discourse?  This isn't Jeopardy -- answer 
first, then question.

+ I also need some help for cursor control. This is a DOS-command line
+ controlled program, and I want some progress indicators. For that
+ purpose I need to move the cursor back some spots, or up one line.
+ 
+ 
+ Apreciate any suggestions you might have...
+ 
+ 
+ 
+ Sigmund S.
+ baal@c2i.net

You didn't respond to that part of the post at all.  Why are we seeing 
it again?

You are lazy and presumptuous.  Please come back some other time, when 
you have learned something about diligence and propriety.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: 18 Jul 1999 00:07:04 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: newbie needs help!
Message-Id: <x7908eiot3.fsf@home.sysarch.com>

>>>>> "BG" == Brian Gilman <gilmanb@vuser.union.edu> writes:

  BG>     shift(@array_of_words) = $word_list;

that is a very funny looking peice of code. the rest of your code looked
decent for a newbie but where did you get that one from?

did you read the docs on what shift does?

	=item shift ARRAY

	=item shift

	Shifts the first value of the array off and returns it,
	shortening the array by 1 and moving everything down.

nowhere does it mention adding elements to an array. try its sibling
push and make sure you read the docs before using it as it won't work
with the syntax you have above.

and a far simpler solution is:

	@array = <CONF> ;
	chomp array ;

	close CONF ;

that's all folks!

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


------------------------------

Date: Sat, 17 Jul 1999 22:44:17 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: newbie needs help!
Message-Id: <MPG.11fb098df215fb42989cf1@nntp.hpl.hp.com>

In article <x7908eiot3.fsf@home.sysarch.com> on 18 Jul 1999 00:07:04 -
0400, Uri Guttman <uri@sysarch.com> says...
> >>>>> "BG" == Brian Gilman <gilmanb@vuser.union.edu> writes:
> 
>   BG>     shift(@array_of_words) = $word_list;
> 
> that is a very funny looking peice of code. the rest of your code looked
> decent for a newbie but where did you get that one from?

I don't think you noticed that his file-open diagnostic reported !$ on 
failure, and that his subroutine returned after the first iteration of 
the input loop, not after the loop.  Not that 'decent', I would say.

 ...

> and a far simpler solution is:
> 
> 	@array = <CONF> ;
> 	chomp array ;

Ook.  Bloody bareword misprint there.  Of course, in line with my 
environmentally-correct goal of conserving the world's limited supply of 

semicolons, I would write it thus:

      chomp(@array = <CONF>);

So I couldn't have made the misprint by naming the array twice.  :-)


-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: 18 Jul 1999 04:17:59 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: newbie needs help!
Message-Id: <x7673iid6w.fsf@home.sysarch.com>

>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:

  LR> In article <x7908eiot3.fsf@home.sysarch.com> on 18 Jul 1999 00:07:04 -
  LR> 0400, Uri Guttman <uri@sysarch.com> says...
  >> >>>>> "BG" == Brian Gilman <gilmanb@vuser.union.edu> writes:

  BG> shift(@array_of_words) = $word_list;

  >> that is a very funny looking peice of code. the rest of your code
  >> looked decent for a newbie but where did you get that one from?

  LR> I don't think you noticed that his file-open diagnostic reported
  LR> !$ on failure, and that his subroutine returned after the first
  LR> iteration of the input loop, not after the loop.  Not that
  LR> 'decent', I would say.

i said for a newbie. we have seen much worse. the total misgrok of shift
and its syntax melted thru the glacial armor of my coding heart.

  >> @array = <CONF> ;
  >> chomp array ;

  LR> Ook.  Bloody bareword misprint there.  Of course, in line with my
  LR> environmentally-correct goal of conserving the world's limited
  LR> supply of semicolons, I would write it thus:

  LR>       chomp(@array = <CONF>);

i know the idiom. i was just trying to be nice and simple for the
newbie. and i get attacked for it! i will never be nice again to anyone
here. this is such a nasty group. :-(

uri


-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


------------------------------

Date: 18 Jul 1999 05:57:13 GMT
From: tgy@chocobo.org (Neko)
Subject: Re: Old database is erased when I add new information
Message-Id: <7mrqbp$dq6$0@216.39.141.200>

On 17 Jul 1999 16:18:57 GMT, stanley@skyking.OCE.ORST.EDU (John Stanley)
wrote:

>In article <7mp493$2c8$0@216.39.141.200>, Neko <tgy@chocobo.org> wrote:
>>You're the head chef.  You say what goes in the pot and what doesn't.  The
>
>Excuse me? I can tell them what they can and cannot do, but the only way
>to stop them is to not give them the code.

You include a license that forbids modifying/distributing the code.  If you
don't include a license, the code is still copyrighted.  If/when your users
make changes to the code, tell them not to and by all means don't condone
their actions by bending over backwards to accommodate these changes.

>>>Except to do otherwise is "not the perl way" and people are ridiculed
>>>when they ask how not to have open source.
>>
>>I say "open source" in reference to the license you use for your code.  The
>
>And I a say "open source" in the sense of this thread, which is giving
>the source code to people. It has nothing to do with licenses.

You are using a term with a well-defined meaning to mean something else.
There is a difference between giving the source code to people and letting
them modify/distribute it.

>>>Unless you know the situation, please don't tell me what I don't have to
>>>do.
>>
>>You don't have to write code.  
>
>Thanks. 

You're welcome.

>>If the programs differed in only one small operation, then you have
>>exaggerated the enhancements your two users have made.  
>
>I see. If the changes are small then they aren't really changes. I've
>just exaggerated the situation by calling them changes.

You have snipped the rest of the paragraph and are arguing against ghosts of
your own creation.  I was trying to give you the benefit of the doubt, but if
you insist that the changes are small and it taxes your ability to cope with
them, then so be it.

>>>If I don't merge, I have to program it. Where is this time I save by
>>>having people send me patches? 
>>
>>Agreed.  Ignored patches are worthless.  
>
>If you notice carefully, my statement did not mention value, only time.

If you notice carefully, you have snipped the rest of the paragraph, which
explicitly states that time is what is being wasted.

>>I assumed you would say so in a license.  I
>
>Is every piece of code you write covered by a license?

Either a license or a copyright.  You have judiciously snipped the next
sentence about having a copyright.  Keep this up, and I will invoke the name
of a certain Nazi dictator and put an end to this.

>>So did you or did you not give permission to modify your code?  
>
>I did, but that is not relevant. The discussion is about a reason to
>hide code, which is to prevent people from changing it.

You gave them permission to change the code.  They changed the code.  There
is no reason to hide it from them.

>I am using this
>example of people changing the code to provide counter-argument to the
>claim that giving the source to people so they can change it is a Good
>Thing that we all must want.

My own claim is that allowing people to change the source is not a Bad Thing.
My other claim is that promising people that you will blindly accept all
their changes in your next release is a Stupid Thing.

>>The issue is lusers thinking you're an idiot because they broke something and
>>it's your fault for allowing them to do it.  
>
>No, that is not the issue. "Allowing them" is not part of the equation.
>When they use ASCII mode to transfer they don't even know that they have
>changed it, so they can't be thinking I allowed them to change it.

Even worse for your beseiged reputation.  The luser *knows* he didn't change
the code, so the luser accuses you of giving broken software to begin with.

I repeat:  YOU JUST CANNOT WIN AGAINST STUPIDITY.

Hiding your source won't stop the luser from calling you an idiot, it just
gets you ridiculed by denizens of this newsgroup as well.

>>Deliberate modification is handled with a license and a good lawyer.
>
>Licenses do not prevent anything. They only give you some chance that
>the money you spend on a lawyer to sue them (after the fact) will be
>recoverable. If licenses prevented anything, then there would be no
>software piracy.

If hiding the source prevented anything, then Microsoft wouldn't have a legal
team hunting down software piracy.

-- 
Neko | tgy@chocobo.org | Will hack Perl for a moogle stuffy! =^.^=


------------------------------

Date: Sun, 18 Jul 1999 03:15:30 -0600
From: "Anthony Kirby" <akirby@cableregina.com>
Subject: Perl, Apche, Win32 and Crypt Question
Message-Id: <3791a866.0@204.83.142.253>

I am trying to create a simple cgi script that will allow me to add, modify
or remove users and passwords from the Apache .htpasswd file.  I am running
Apache on a Windows System which defaults the password encryption to MD5.  I
have tried the 'crypt' function but it doesn't crypt the password in MD5.
Could someone please help me on this...


Thanks;
Confused
akirby@cableregina.com





------------------------------

Date: Sun, 18 Jul 1999 01:13:52 -0400
From: "Ethan H. Poole" <ehpoole@ingress.com>
Subject: Re: pure perl solution for Blowfish, DES or IDEA?
Message-Id: <37916290.AE1730F5@ingress.com>

[posted and emailed]

Rainer Hillebrand wrote:
> 
> Does anyone know a pure perl solution for Blowfish, DES or IDEA? I can't
> install the known modules on the web server because I only have a ftp
> access to my web server. Even if a pure perl script is rather slow it is
> better than nothing.

I haven't converted either of those three, but I have converted Sapphire
(a streaming cipher algorithm) into pure perl.  It isn't blazingly fast,
but for small strings of a few K at a time it isn't bad, it's just when
you start working with files of 1MB or so that you notice the pure perl
solution taking a minute or more vs. the pure C solution taking a fraction
of a second.

On the downside, I'd have to find a way to cripple it before I could give
it to you <sigh>.  Like most in the US who work with cryptography from
time to time, I am not particularly fond of the ITAR restrictions on
export... it's insane I can't export even an imported technology.

-- 
Ethan H. Poole           ****   BUSINESS   ****
ehpoole@ingress.com      ==Interact2Day, Inc.==
(personal)               http://www.interact2day.com/


------------------------------

Date: Sat, 17 Jul 1999 22:30:18 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Question: optimized method for finding the maximum value in an array
Message-Id: <MPG.11fb0638c2e23c46989cee@nntp.hpl.hp.com>

In article <379147DA.7255568@home.com> on Sun, 18 Jul 1999 03:20:40 GMT, 
Rick Delaney <rick.delaney@home.com> says...
 ... 
> Since I mentioned builtin I thought I should add it to this benchmark.
> 
> use builtin;
> timethese (
>   30000,
>     {
>      'Larry1' => sub { larry1(@a) } ,
>      'Larry2' => sub { larry2(@a) },
>      'UseSort' => sub { usesort(@a) },
>      'Builtin' => sub { builtin::max(@a) },
>     }
> );
> __END__
> 
> Benchmark: timing 30000 iterations of Builtin, Larry1, Larry2,
> UseSort...
>    Builtin:  1 wallclock secs ( 0.75 usr +  0.00 sys =  0.75 CPU)
>     Larry1:  9 wallclock secs ( 8.33 usr +  0.00 sys =  8.33 CPU)
>     Larry2:  9 wallclock secs ( 8.89 usr +  0.00 sys =  8.89 CPU)
>    UseSort: 25 wallclock secs (25.33 usr +  0.01 sys = 25.34 CPU)

Ah.  Now that feels good!  As the algorithms are the same, the benefit 
of the module comes from its machinations being done in C, rather than 
in Perl as in my code.  

The original poster said:  "Preferred optimizations not requiring 
external modules are, of course, welcome and encouraged!"  From its 
name, I don't know if 'builtin' is 'external' or not, but it certainly 
is the way to go if speed in this little area is critical.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: 18 Jul 1999 04:14:24 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Regular expression question (Problems with parsing ascii go diagrams)
Message-Id: <slrn7p36mb.c9j.abigail@alexandra.delanet.com>

Toni Cornelissen (toni@dse.nl) wrote on MMCXLVI September MCMXCIII in
<URL:news:01bed090$df71d580$LocalHost@default>:
** 
** To match a line of a ASCII go diagram,
** I came up with the following code:
** 
**     /(\d{0,2})\s+((?:[\.OX\d] |\d\d)+)\s*\1/
** 
** First the line number: (\d{0,2}) 
**   The number does not have to be present an can be 99 at most.
** Then at lease one white space character: \s+
** Followed by characters identifying a stone: ((?:[\.OX\d] |\d\d)+)
**   Maximal 99 move in a board.
** Eventually some white space \s*
** And at last the same number the line started with.
** 
** Unfortunately the line:
** 
**     3  . X . 4 O . . 3
** 
** Does no generate:
**  
**     $1 = 3
**     $2 = . X . 4 O 
** 
** But:
** 
** First:
**     $1 = 
**     $2 = 3 

Indeed. That is because you are likely to have leading spaces (in fact, if
there is no line number, the regex *requires* leading whitespace), and
(\d{0,2}) can be a string of zero characters. Hence, your first match
0 digits, then the whitespace, the '3' is matched by ((?:[.OX\d] |\d\d)+)
and \s*\1 can match an empty string.

** And second:
**     $1
**     $2 = X . 4 0 . . 3 
** 
** Can someone tell me what I'm doing wrong 
** and what the correct expression I should use is.

You should anchor your expression, and get everything from the beginning
upto and including the part you are interested in.

   /^            # The beginning of the line.
    \s*          # Initial whitespace (might be empty).
    (            # Group 1.
     \d?\d?      # Possible line number.
    )            # End group 1.
    \s+          # Whitespace after the line number.
    (            # Group 2.
     (?:         # Group 3 - non capturing.
      [.OX\d]\   # A dot, O, X or a single digit, followed by a space.
      |          # or
      \d\d       # 2 digits.
     )+          # End group 3, repeated one or more time.
    )            # End group 2.
    \s*          # Optional whitespace.
    \1           # If a line number was given, it has to be repeated again.
   /x;

Note that the above regex will fail to parse " . . .", as the last .
is not followed by a space. Your original regex demanded a trailing
space as well, and I copied that demand.


** The way I read "The rules of regular expression matching" (page 60
** and further of Programming Perl, Larry Wall e.a.) this is the
** correct expression. I obvious read that paragraph wrong.


I can't recall a regex about parsing go diagrams in the Camel.... ;)



Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


  -----------== 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: 18 Jul 1999 04:21:35 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: split()
Message-Id: <slrn7p373v.c9j.abigail@alexandra.delanet.com>

skyfaye@my-deja.com (skyfaye@my-deja.com) wrote on MMCXLVII September
MCMXCIII in <URL:news:7mr8or$n1b$1@nnrp1.deja.com>:
() Hi,
() 
()   Can someone tell me why the split function splits the string into 3
() elements instead of 2?
()
() $line = "   Boston     87";   # All the white spaces are spaces

Well, that's related to the old question, "if I want to fence a kilometer,
and have a fencing pole every metre, how many fencing poles do I have?".

In your case, you have streches of fence, how many fencing poles do you
have?


(Yes, I know it doesn't hold if there's a strech of fence at the end,
 but that's not happening here, is it?)


The man page about 'split' explains this.


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: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 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.  

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 V9 Issue 180
*************************************


home help back first fref pref prev next nref lref last post