[6849] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 474 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 14 07:07:14 1997

Date: Wed, 14 May 97 04:00:23 -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           Wed, 14 May 1997     Volume: 8 Number: 474

Today's topics:
     'MacPerl' and 'format' problem <klang@daimi.aau.dk>
     array of arrays <ahenig@iil.intel.com>
     Re: CGI/perl execution problems..... <zonycat@flash.net>
     control-M makes for very long $_ <t.lewisflood@elsevier.com>
     Re: Help with Perl <rootbeer@teleport.com>
     Re: inclu-OR in regex (Jahwan Kim)
     Re: indenting white space <dorman@s3i.com>
     Re: indenting white space <rootbeer@teleport.com>
     Re: index question (Mike Stok)
     Learning PERL <dshilson@plym.ac.uk>
     Re: Mime types for .cgi, .pl ?? (Magnus Bodin)
     Minor bug in Configure on HPUX 10.20 using gcc perl 5.0 <sfairey@metrica.co.uk>
     Re: More problems with FileHandle <rootbeer@teleport.com>
     Need help for CGI/Perl... (Timo Wende)
     Re: New draft of scripting white paper (Ray Johnson)
     Re: Pattern Matching Help Needed!! (Mike Stok)
     Re: printer (Brand and Karina Hilton)
     Randal Schwartz (Michael Lauzon)
     Re: Randal Schwartz (A. Deckers)
     Re: Regex problem - removing trailing form input <flg@vhojd.skovde.se>
     Re: Sorting by date with format MMDDYY (Lack Mr G M)
     Re: Sorting by date with format MMDDYY (Craig Berry)
     telnet client <mrab100@cam.ac.uk>
     Re: telnet client (A. Deckers)
     Re: telnet client (A. Deckers)
     Re: Timing Out While waiting for user input (Mike Stok)
     Undump Question... <sarah@ecl.wustl.edu>
     Update: Comparing C, Lisp, Tcl, Perl, Python, Java, & S <john.watton@alcoa.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Wed, 14 May 1997 11:31:18 +0200
From: Karsten Lang Pedersen <klang@daimi.aau.dk>
Subject: 'MacPerl' and 'format' problem
Message-Id: <33798666.15FB@daimi.aau.dk>

Should I be aware of anything before using formats under MacPerl?

When I try to compile/execute a script containing a format, MacPerl
tells me, that it is not terminated properly, eventhough the format
is terminated with a dot (.). I have tryed terminating with dot-newline
and dot-newline-return and dot-return combinations, but nothing seems
to work.

What should I do?

-- 
Karsten Lang (mailto:klang@daimi.aau.dk http://www.daimi.aau.dk/~klang)


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

Date: Wed, 14 May 1997 11:40:26 +0300
From: Allon Henig <ahenig@iil.intel.com>
Subject: array of arrays
Message-Id: <33797A7A.371F@iil.intel.com>

Hi ,
	is it possible to build an array of arrays like:

	@Array1= ('a','b','c');
	@Array1= ('x','y','z');
	push (@BIGARRAY,@Array1);
	push (@BIGARRAY,@Array2);	

	now, how do I print $BIGARRAY[0] data (which ofcourse must be:
		'x' 'y' and 'z') ???

			Thanks, 	Allon


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

Date: Mon, 12 May 1997 00:06:05 -0700
From: Zonycat <zonycat@flash.net>
Subject: Re: CGI/perl execution problems.....
Message-Id: <3376C15D.5A8A@flash.net>

HEY I FIGURED IT OUT!!!!!!!!

Spending a whole weekend at this has been no fun. More hints for people
having similar problems....

MS Internet Explorer will by DEFAULT set up a cache directory in
"c:\windows\Temporary Files".  Well perl HATES this!  This cach
directory need to be moved to some other places with the standard dos
naming convention.  Also the directory must be executable.  This really
burned me.  Also the registry MUST include also the .cgi entry as
described in the earlier posts for .pl.  [ The local in registry:
"HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\W3Svc\Parameters\Script
Map" ] (don't forget the %s at end of line i.e. c:\perl\bin\perl.exe %s)

BTW, if you do not have the registry setup correctly, you get the HTTP1.
500 error.  Also after you modify the registry, besure to reboot your
PC.

If you never modified your registry before, please make a backup copy
first.

Also, in case some of you missed it... Get rid of the #! line in your
CGI script for WIN95 executions.  Make sure you have a path for perl
correct in Autoexec.bat and that both .cgi and .pl are associacted with
perl.exe (full path) for file types. 

There have been other useful posts here, but I do not have them handly.

THANKS for all that sent me mail for suggestions.  I am VERY grateful.  

Dennis

Zonycat wrote:
> 
> I have a mess here.  I know, what a way to start.  Here's the scoop.....
> 
> I am trying to run cgi scripts, even the example scripts found in the
> CGI code (index.htm and tryit.cgi). On  my local PC, I can not get them
> to run.  Here is waht I have installed...
> 
> * WIN95 with perl5 in my c:\perl directory tree.  I have CGI installed
> too in its directory tree.
> * I have associated .pl, .cgi with the perl script. Even followed
> directions in FAQ 4.10
> * Check registry for activeware.  Found it is correct for perl5.
> * Autoexec.bat has the perl directory in path.
> * Installed MS PWS (Personal Web Server)
>       Made sure that the W3svc/parameters/Script Map has the .cgi, .pl
> entries to be
>       c:\perl\bin\perl.exe %s
> * Using MS Internet Explorer as default.  (have Netsacpe, but makes no
> difference which is default)
> * In my webshare/wwwroot directory, I have placed the index.htm,
> tryit.cgi, and even CGI.pm .
>    (BTW, CGI.PM is in its lib directory too)
> 
> When I call the tryit.cgi script from the Index.htm file, some perl
> execution window pops up and disappears very quickly.  Only notice
> something about can't open.....  Window is way too quick to read.  Guess
> it is trying to open a file in the "c:\windows\Temporary Internet Files"
> directory.  If that is the case, how can I
> prevent that from happening?  I know you can not use these long file
> names as seen above.
> 
> Netscape, just wants me to save the cgi script it is trying to execute.
> 
> If I execute the cgi script from the command line in a DOS window, it
> states that I am in offline and to enter the name=value pairs.  I see
> why that is happening because the argv variables are not set properly.
> If I enter name=value pairs, then I see in the window a 'html' generated
> script form the tryit.cgi script.
> 
> Basically what am I doing wrong, missing?  I want to execute cgi scripts
> on my local PC.  All the parts seem to be there, but not completly it
> seems.  What else do I need to do?  Am I missing some other part?  Any
> other information needed?
> 
> Thanks, for any help,
> 
> Dennis
> P.S.
> I accept partial answers.  You partial credit is better than nothing at
> all :))


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

Date: Mon, 12 May 1997 14:30:07 -0700
From: Tom Lewis-Flood <t.lewisflood@elsevier.com>
Subject: control-M makes for very long $_
Message-Id: <33778BDF.3506@elsevier.com>

I'm debugging someone's perl cgi script and I hardly know perl, so here
it goes:

1. I look at a file with less and I see control-Ms where I would expect
to see newlines. I presume this is because the file was created with
DOS.

2. The script is supposed to print the file between html <PRE> tags.
When the script says, 
    while  (<FILEHANDLE>) {
        print;
    }
and nothing comes out, but when I change the file with the commandline,
	perl -p -i -e 's#^M#\n#g' filename.txt
it outputs the file properly.

3. I've tried things like,
    s#\cM#\n#g;
    while  (<FILEHANDLE>) {
        print;
    }
but it doesn't seem to change a thing.

I could really use a hand. Thanks.

-- 
Tom Lewis-Flood
Elsevier Science Inc.
655 Avenue of the Americas
New York, NY 10010-5107
tel:	212-633-3855
fax:	212-633-3685
e-mail:	t.lewisflood@elsevier.com


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

Date: Mon, 12 May 1997 08:17:44 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Brad P. Crochet" <bcrochet@yavin.thinkstream.com>
Subject: Re: Help with Perl
Message-Id: <Pine.GSO.3.96.970512081121.2793D-100000@kelly.teleport.com>

On 11 May 1997, Brad P. Crochet wrote:

> Newsgroups: comp.lang.perl

There is no comp.lang.perl. Tell your newsadmin to read the frequent
posting in news.announce.newgroups about bogus newsgroup names, and to set
up comp.lang.perl.misc for you to use instead of comp.lang.perl. 

> Subject: Help with Perl

Speaking of frequent postings, be sure to find the one in this newsgroup
about choosing good subject lines. _Every_ posting here should have to do
with help with perl! :-) 

> I'm getting some odd warnings every time I start perl. This is what I am
> getting: 
> 
> warning: setlocale(LC_CTYPE, "") failed.
> warning: LC_ALL = "(null)", LC_CTYPE = "(null)", LANG = "us",
> warning: falling back to the "C" locale.

Sounds like somebody has installed the 5.004 beta without letting you
know. Check out perldelta(1) and perllocale(1), and see about asking your
sysadmin to fix your machine's locale support and to not install beta
software without letting you know. :-) 

Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: 14 May 1997 09:31:45 GMT
From: jahwan@supernova.math.lsa.umich.edu (Jahwan Kim)
Subject: Re: inclu-OR in regex
Message-Id: <slrn5nj1k1.d3i.jahwan@supernova.math.lsa.umich.edu>

On Tue, 13 May 1997 20:50:38 -0700, alex <alex.t.silverstein@bender.com> wrote:
> I want to match the letters a b and c in a string at least once
> but in any order. The part I don't get is how to say "in any order"
> in a regex (I can't seem to find this explained well in 
> "Learning Perl"). I tried the following:
> 
> $dil ="acb"
> $dil =~ s/(a)+(b)+(c)+/something/
[snip]
(Put ';' at the end of statements, like this; see?)

    The pattern you have above matches one or more occurence of a followed
by one or more occurence of b followed by one or more occurence of c.
    I can't think of general way, being a novice myself.  But in this case,
    
$dil =~ s/([abc])(?!\1)([abc])(?!(\2|\1))([abc])/something/;

works fine in all examples I tried.  I have the feeling, though, 
that this is far from efficient.

Jahwan

    



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

Date: 12 May 1997 07:37:23 -0400
From: Clark Dorman <dorman@s3i.com>
Subject: Re: indenting white space
Message-Id: <dwwp4c45o.fsf@s3i.com>


James Littlejohn <jameslj@interlog.com> writes:
> new to perl here...is there a program to automatically format the
> indents in perl scripts. thx

Get emacs.  Get cperl mode for emacs.  Select the whole buffer
(Cntl-space at top, Esc->).  Auto-indent (Esc-Cntl-\).  Done.

Cperl-mode understands (well, to a relatively high degree) what is
going on in perl code, and it's got a bunch of user-selectable
features.  As an added bonus, you get emacs, in which you can run
perl, and debug it, emacs will color the code, and it slices, dices,
and makes juliene fries.

In general, the problem with an auto-indenter is that it has to
"understand" the code to know when to indent.  The only thing that
"understand" perl code as well as Tom C, Randal Schwartz, etc is perl
itself.  

-- 
Clark Dorman				"Evolution is cleverer than you are."
http://cns-web.bu.edu/pub/dorman/D.html                -Francis Crick


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

Date: Mon, 12 May 1997 08:11:01 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: James Littlejohn <jameslj@interlog.com>
Subject: Re: indenting white space
Message-Id: <Pine.GSO.3.96.970512080853.2793C-100000@kelly.teleport.com>

On Sun, 11 May 1997, James Littlejohn wrote:

> new to perl here...is there a program to automatically format the
> indents in perl scripts. thx

It sounds like you want a Perl prettyprinter, but there isn't one that's
able to reliably handle all of Perl. I recommend doing manual formatting
using a programmer's editor, like vi or emacs. (Of course, if you keep
things indented as you go along, you won't have this trouble. :-) 

Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: 12 May 1997 14:43:29 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: index question
Message-Id: <5l7aah$rg4@news-central.tiac.net>

In article <33754210.6B22@iil.intel.com>,
Allon Henig  <ahenig@iil.intel.com> wrote:
>Hi I bumped into a very paculier behavior of the index function
>
>I have the following code:
>
>$line = "Allon HENIG";
>$word_to_search = "henig"; # notice the lower case 
>$start = index ($line,/$word_to_search/i);
>print $start;
>
>The out put is $start = 0 (?!?!?!?!?!?!?!)

That's because index works with strings not patterns, you might say

  $line = "Allon HENIG";
  $word_to_search = "henig";
  $start = index (lc ($line), lc($word_to_search));

which should set start to 6.

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com                |      Pencom Systems Administration (work)


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

Date: Fri, 09 May 1997 13:19:47 -0700
From: Darren Shilson <dshilson@plym.ac.uk>
Subject: Learning PERL
Message-Id: <337386E3.259A@plym.ac.uk>

Hi,

I'm relatively new to PERL programming and would really like to find out
as much as I can about the language. However being a poor student I
can't fork out loads of money on books, but I've got free Internet
Access, so if you know of any on-line tutorials, e-zines, e-books, etc,
I'd love to hear from you.

Thanks A Lot

Darren


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

Date: Mon, 12 May 1997 14:56:48 GMT
From: Magnus.Bodin@tychonides.se (Magnus Bodin)
Subject: Re: Mime types for .cgi, .pl ??
Message-Id: <33792f78.253279296@news1.telenordia.se>

Zonycat <zonycat@flash.net> wrote:

>I am having no luck trying to locall display my cgi scripts.  I have
>installed PWS and it works for finding my htm file.  When it tries to
>execute the cgi file, a window flashes and it appears to say something
>about not finding something in the Temporary Internet directory.  Why on
>earth it is trying to go there I have no idea.  I did get the "source "
>of the cgi script to display if I associated the .cgi with a mime type
>of 'text/htm'.  I know that is not right.
>
>Again to be clear, my path to perl in the registry is:
>C:\Perl\bin\Perl.exe  %s
>even put CGI.pm in my 'home directory' (wwwroot).
>have my cgi script and htm file in there too.
>   (did this to get rid of any 'path problems'
>++++++++++++++++++++++++++++++

OK. The CGI.pm should stay in your perl library. (i.e. c:\Perl\lib);

VERY IMPORTANT: 

You should place your cgi-script in a cgi-executable-directory,
e.g. c:\iispub\scripts. With the "Internet Service Manager" you should
check that the library containing your cgi-scripts have the Execute
access check-button checked. 
(Start the ISM, click on Directories tab, click on library and use
"Edit properties", Look in the access box

Check also that the registry key HKEY_CLASSES_ROOT\.pl is set to
(default) Perl  and the key HKEY_CLASSES_ROOT\Perl\Open\Command is set

to (default) perl.exe %1 %*

>
>Got rid of the #! in the cgi script.

why? They are just comments


And, by the way, RTFM!



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

Date: Wed, 14 May 1997 10:46:17 +0100
From: Simon Fairey <sfairey@metrica.co.uk>
Subject: Minor bug in Configure on HPUX 10.20 using gcc perl 5.003
Message-Id: <337989E9.51BC@metrica.co.uk>

Hi,

If this does not ring a bell with anyone then I will provide further
details but when I ran Configure and selected gcc as my compiler one of
the default flags was -Aa which I believe is for HP's cc and not gcc.
Removing -Aa from the list leads to a problem free compile but I thougt
I'd mention it as I am sure it should not really appear in the default
flags list.

Simon


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

Date: Mon, 12 May 1997 08:05:23 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Gene Johannsen <gej@spamalot.mfg.sgi.com>
Subject: Re: More problems with FileHandle
Message-Id: <Pine.GSO.3.96.970512080221.2793B-100000@kelly.teleport.com>

On 11 May 1997, Gene Johannsen wrote:

> package Foo;
> 
> sub new {
>     my $class = shift;
>     my $file = shift;
> 
>     my $fh = new FileHandle ">>$file";
> 
>     return bless \$fh, $class;

As others have said, I think you want simply C<bless $fh, $class> there,
if you _must_ bless it. (Why not just let it be a FileHandle? I think
that's what you really want. Unless you want it to contain a FileHandle,
or something like that.)

> }
> 
> sub write {
>     my $self = shift;
>     confess "wrong type" unless ref $self;
> 
>     print $fh "This is a test\n";

What's $fh? :-)

> }

Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Mon, 12 May 1997 13:43:12 GMT
From: T.Wende@mail-me.com (Timo Wende)
Subject: Need help for CGI/Perl...
Message-Id: <5l76n4$ap5@horus.mch.sni.de>

Hi *.*,

Is anybody there, who can tell me what the error-message
------------------------------------------------------------------------------------------------------------------------------
500 Server Error

The server encountered an internal error or misconfiguration and was
unable to complete your request.

Please contact the server administrator, webmaster@sporthaus.com and
inform them of the time the error occurred , and
anything you might have done that may have caused the error.

Error: HTTPd: malformed header from script
/usr/local/etc/httpd/htdocs/sport/cgi-bin/formmail.cgi 
------------------------------------------------------------------------------------------------------------------------------
means? I have access to the cgi-bin-directory and the file
"formmail.cgi" have all needed rights (777).

IMO is the problem not the Perl-Script, it seems to be something in
server-configuration.

Please excuse my terrible english :) 

Best regards, Timo




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

Date: 12 May 1997 15:48:12 GMT
From: rjohnson@Sun.COM (Ray Johnson)
Subject: Re: New draft of scripting white paper
Message-Id: <5l7e3s$nhn$1@engnews2.Eng.Sun.COM>

Cimarron Taylor (cimarron@dis.org) wrote:
: This may just be wishful thinking, but I predict the distinguishing 
: characteristics of professional programmers of the next century will be 
: the algorithms they know, the problems they can solve and the technologies 
: they understand and not knowledge of a particular brand of general purpose 
: language or operating system.  The "real" programming problems of the next 
: century will either require more sophisticated programming paradigms than 
: in use today or a radically different method for creating programs altogether.  
This is one of the basic points John is trying to make in the scripting
white paper.  What you call "professional programers", however, John
would call a systems programmer.  The point of scripting - and other
high level solutions - is that there will never be enough systems programmers
to do all the work that's needed.  Scripting and domain specific programming
allow less sophisticated programmers take on more of the load.

: > Tcl is interesting in this space because it is often used to create domain
: > specific languages.  The extension mechanism in Tcl is powerful enough to
: > develop any type of new command, language construct, or programming paradigm
: > that makes sense for a given domain.  That's really what application level
: > scripting languages are all about.  Tcl is just one easy way to do that.

: I disagree. The domain-specific languages you can build with Tcl 
: are pretty much limited to the variations of the simple procedural
: constructs Tcl and most other shell languages have.  Tcl is really
: just a variation of /bin/sh which makes it easy to run commands in 
: the same process.  

: To put it another way, I've never heard anyone speak of extending the 
: "programming paradigm" of /bin/sh when they create a new executable.
: Why should that terminology apply to Tcl?

This show that you don't really know how the extensions mechanism in
Tcl works (not that many Tcl users do either).  Tcl is not /bin/sh
and is much more flexable and extendable than /bin/sh or most any
other programming language (except lisp and some others).  For example,
I've made a declaritive based extension language for an agent system
based on Tcl.  Several people have made OO versions of Tcl for thier
needs.  The key is that you can create new control structures very easily.

So your comments beg the question.  What defines domain-specific?
I can think of many domain specific languages that I have seen that
simply add new commands.  You imply that that isn't enough.  Why?

Ray



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

Date: 12 May 1997 10:56:04 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Pattern Matching Help Needed!!
Message-Id: <5l6t04$6jm@news-central.tiac.net>

In article <33768ba1.5083407@nntp.a001.sprintmail.com>,
Frank Fisher <frank@primemail.com> wrote:
>I have a string I'm trying to match on:
>
>$filter = "this is a test string 1234****";
>$str = "1234****";
>
>I get the following perl error:
>
>/*/: ?+* follows nothing in regexp at test.pl line 58
>
>this is line 58:
>
>if ($str =~ /$filter$/)
>
>Is there anyway to turn off perl trying to see the * char as a special
>character?  I need to look at the last part of the string which is
>1234****

You can escape any characters which might be special to perl by using a \
in the string.  In perl 5 there is the quotemeta operation which can be
used in several ways, one is to use \Q ... \E (start quoting
metacharacters and end) in a double quotish context e.g. 

  if ($str =~ /\Q$filter\E$/)

another way might be to say

  $escapedFilter = quotemeta $filter;
  if ($str =~ /$escapedFilter$/)

which is similar to the way it chould be done in perl 4.xxx and before:

  ($escapedFilter = $filter) =~ s/(\W)/\\$1/g;

Hope this helps,

Mike
-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com                |      Pencom Systems Administration (work)


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

Date: Mon, 12 May 1997 18:21:02 GMT
From: bkhilton@netcom.com (Brand and Karina Hilton)
Subject: Re: printer
Message-Id: <bkhiltonEA2yz2.Cw4@netcom.com>

In article <33772B12.3DAD@mathematica-mpr.com>,
the count  <eglamkowski@mathematica-mpr.com> wrote:
>how does one go about sending STDIN to the printer?
>"Leraning Perl" seems to skirt about the issue, talking about
>if you were to send something to the printer, be sure to do this
>that or the other thing (in particular, in the chapter on formats,
>but elsewhere too), but they never actually tell you *how* to send
>things to the printer.
>i want to believe there should be some platform indepent way, like
>a special filehandle (PRN?), so that you could do something like:
>print PRN "whatever";

Sorry, there isn't.  Printing is a very platform-dependent thing.


	Brand


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

Date: Mon, 12 May 1997 16:28:57 GMT
From: ce940@torfree.net (Michael Lauzon)
Subject: Randal Schwartz
Message-Id: <EA2tsA.HF9.0.bloor@torfree.net>

This is a question for Randal Schwartz.

I have a chat script written in Perl, but everytime I try to run it...it 
gives me parse errors; it's a web-based chatsite.  I would really 
appreciate it if you would take a look at it, though I will need to email 
it to you...and for that I will need your email address.  I would really 
like to get my chatsite up and running, but I can't get the script to 
work.  

Michael

ce940@freenet.toronto.on.ca
-- 
Michael
Free email address: http://www.hotmail.com/

'Eat, drink, and be merry, for tomorrow you may work.'


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

Date: 12 May 1997 17:01:25 GMT
From: I-hate-cyber-promo@man.ac.uk (A. Deckers)
Subject: Re: Randal Schwartz
Message-Id: <slrn5nej75.h1i.I-hate-cyber-promo@news.rediris.es>

In comp.lang.perl.misc,
	ce940@torfree.net wrote:
>This is a question for Randal Schwartz.
[...]

Ferchrissakes, if you have a question for Randal Schwartz, send it to
him by email, but don't broadcast it all over Usenet.  _If_ he feels
like answering, he'll do so, and if he doesn't, he won't, but where's
the logic in consuming resources on thousands of news servers all over
the world to send a message to a _single_ person?

followup set

HTH,

Alain

-- 
Perl information: <URL:http://www.perl.com/perl/>
    Perl archive: <URL:http://www.perl.com/CPAN/>
        Perl FAQ: <URL:http://www.perl.com/CPAN/doc/FAQs/FAQ/>
>>>>>>>>>>>>> NB: comp.lang.perl.misc is NOT a CGI group <<<<<<<<<<<<<<


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

Date: 14 May 97 09:08:53 GMT
From: "Fredrik Lindberg" <flg@vhojd.skovde.se>
Subject: Re: Regex problem - removing trailing form input
Message-Id: <01bc6046$73cca560$e20f10c2@odens.di.vhojd.skovde.se>

David M Holmes <david.holmes@bigfoot.com> wrote in article
<EA4JLC.C9y@ciba-geigy.ch>...
>
> # remove trailing form input
> 
> $testurl =~ m/.*?(\?.*)/;
> $testurl =~ s/$1//;
> 
You could do it like this instead:

$testurl =~ s/\?.*$//;

Hope this helps!

/Fredrik
 


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

Date: Mon, 12 May 1997 09:39:10 BST
From: gml4410@ggr.co.uk (Lack Mr G M)
Subject: Re: Sorting by date with format MMDDYY
Message-Id: <1997May12.093910@ukwit01>

In article <33765EF7.44D2BC39@ptconnect.infi.net>, "Jack L. Owens" <jlowens@ptconnect.infi.net> writes:
|> I need to sort an array of filenames by date. Unfortunately they are in
|> the format "aMMDDYY.zip". What would be the simplest way to do this
|> without reinventing the wheel?

 @unsorted = qw( a011297.zip, a011197.zip, a020197.zip );

 sub by_usdate {
    my $aa = substr($a, 5, 2) . substr($a, 1, 4);
    my $bb = substr($b, 5, 2) . substr($b, 1, 4);
    $aa <=> $bb;
 }

 @sorted = sort by_usdate @unsorted;

 print "@sorted\n";


---
----------- Gordon Lack ----------------- gml4410@ggr.co.uk  ------------
The contents of this message *may* reflect my personal opinion.  They are
*not* intended to reflect those of my employer, or anyone else.


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

Date: 12 May 1997 18:05:43 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Sorting by date with format MMDDYY
Message-Id: <5l7m5o$mrn$1@marina.cinenet.net>

Lack Mr G M (gml4410@ggr.co.uk) wrote:
: In article <33765EF7.44D2BC39@ptconnect.infi.net>, "Jack L. Owens" <jlowens@ptconnect.infi.net> writes:
: |> I need to sort an array of filenames by date. Unfortunately they are in
: |> the format "aMMDDYY.zip". What would be the simplest way to do this
: |> without reinventing the wheel?
: 
:  @unsorted = qw( a011297.zip, a011197.zip, a020197.zip );
: 
:  sub by_usdate {
:     my $aa = substr($a, 5, 2) . substr($a, 1, 4);
:     my $bb = substr($b, 5, 2) . substr($b, 1, 4);
:     $aa <=> $bb;
:  }
: 
:  @sorted = sort by_usdate @unsorted;
: 
:  print "@sorted\n";

Pretty much the solution I used.  Being paranoid, I used 'cmp' rather 
than '<=>' on the last line of by_usdate; it sorts the same for all 
filenames following the stated convention, and also avoids runtime 
warnings if nonstandard filenames get into the mix somehow.  I *think* it 
might also be more efficient, as it avoids two string-to-int conversions 
on each compare.

---------------------------------------------------------------------
   |   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: Mon, 12 May 1997 15:56:30 +0100
From: Matthew Bernstein <mrab100@cam.ac.uk>
Subject: telnet client
Message-Id: <Pine.SOL.3.96.970512155422.29610A-100000@ursa.cus.cam.ac.uk>

I wish to write a telnet client using perl, but am not having any success at
connecting the socket. man perlipc has not proved helpful.

Could someone provide me with the code so that I can:

	print SOCK "output"

and

	$in=<SOCK>

please? Many thanks

Matt



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

Date: 12 May 1997 15:11:11 GMT
From: I-hate-cyber-promo@man.ac.uk (A. Deckers)
Subject: Re: telnet client
Message-Id: <slrn5necof.h1i.I-hate-cyber-promo@news.rediris.es>

In comp.lang.perl.misc,
	mrab100@cam.ac.uk wrote:
>I wish to write a telnet client using perl, but am not having any success at
>connecting the socket. man perlipc has not proved helpful.

Why don't you use the Net::Telnet module instead of rolling your own?

Check <URL:http://www.perl.com/CPAN/modules/by-module/Net/>.

HTH,

Alain

-- 
Perl information: <URL:http://www.perl.com/perl/>
    Perl archive: <URL:http://www.perl.com/CPAN/>
        Perl FAQ: <URL:http://www.perl.com/CPAN/doc/FAQs/FAQ/>
>>>>>>>>>>>>> NB: comp.lang.perl.misc is NOT a CGI group <<<<<<<<<<<<<<


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

Date: 12 May 1997 15:34:39 GMT
From: I-hate-cyber-promo@man.ac.uk (A. Deckers)
Subject: Re: telnet client
Message-Id: <slrn5nee4f.h1i.I-hate-cyber-promo@news.rediris.es>

In comp.lang.perl.misc,
	mrab100@cam.ac.uk wrote:
>I wish to write a telnet client using perl, but am not having any success at
>connecting the socket. man perlipc has not proved helpful.

Why don't you use the Net::Telnet module instead of rolling your own?

Check <URL:http://www.perl.com/CPAN/modules/by-module/Net/>.

HTH,

Alain

-- 
Perl information: <URL:http://www.perl.com/perl/>
    Perl archive: <URL:http://www.perl.com/CPAN/>
        Perl FAQ: <URL:http://www.perl.com/CPAN/doc/FAQs/FAQ/>
>>>>>>>>>>>>> NB: comp.lang.perl.misc is NOT a CGI group <<<<<<<<<<<<<<


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

Date: 12 May 1997 14:57:32 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Timing Out While waiting for user input
Message-Id: <5l7b4s$skd@news-central.tiac.net>

In article <33770C5D.50E7@elvis.turner.com>,
Brian Haney  <bhaney@elvis.turner.com> wrote:
>What I am trying to accomplish is asking a user for input. If they 
>do not enter input within a specific amount of time, the program will
>continue.

You could do something like:

#!/usr/local/bin/perl -w

eval {
  local $SIG{ALRM} = sub {die "timed out\n";};
  alarm (60);
  $in = <STDIN>;
  alarm (0);
};

if ($@ and $@ =~ /timed out/i) {
  print "the code timed out\n";
}
else {
  chomp $in;
  print "got '$in'\n";
}

which is similar to the code at
http://www.perl.org/CPAN/doc/manual/html/pod/perlipc/Signals.html (note I
don't catch the case where $@ is set but it isn't because of a timeout...)

Hope this helps,

Mike
-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com                |      Pencom Systems Administration (work)


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

Date: Sun, 11 May 1997 15:21:59 -0500
From: Sarah Burcham <sarah@ecl.wustl.edu>
Subject: Undump Question...
Message-Id: <Pine.SOL.3.95.970511151223.6039B-100000@joplin.ecl.wustl.edu>

I'm trying to speed up some of my perl code by getting it into an
executable binary and am looking for some advice if anybody can help.

First Question:  

As found in the perlrun docs, perl has a -u option which supposedly will
dump core.  That's great -- where does it leave this core file?  I'm on a
Solaris system and have looked in the current working directory, the root
directory, /var/tmp, and /tmp.  I'd assume either the system's perl wasn't
compiled correctly to begin with, or I'm just really overlooking
something.  I tried doing a truss of the process I'd run with perl -u, but
couldn't find any obvious references to where it might be leaving this
core file. 

Second Question:

I found a FAQ that pointed out the undump that comes with TeX as a viable
possibility once I have a core file.  The other suggestion was to build
perl with the unexec() from GNU emacs.  Anybody tried either of these and
if so which one worked?

// Sarah Elizabeth Burcham
// Engineering Computer Laboratories
// sarah@ecl.wustl.edu








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

Date: 12 May 1997 08:28:55 -0400
From: John Watton <john.watton@alcoa.com>
Subject: Update: Comparing C, Lisp, Tcl, Perl, Python, Java, & Scheme (Guile) Using a Floating Point Numerical Test - Point Inside Polygon
Message-Id: <uiv0ox4ag.fsf@alcoa.com>

Comparing C, Lisp, Tcl, Perl, Python, Java, & Scheme (Guile) Using a
Floating Point Numerical Test - Point Inside Polygon

This is an update on a small study I did to compare various computing
languages, especially those interpreted types that seem to get so much
interest for one reason or another. I wanted to know how they compared
to each other syntax wise and performance wise and also how they
compare to languages that have a native compiler available. Others
more experienced in a particular language have offered improvements
that are incorporated. The only change in order was movement of Perl
ahead of Tcl and Guile. Please don't flame me if your favorite didn't
fair well - this test very much favors speed of floating point
numerical calculation.  Please don't be the next person to tell me
that you can embed the C version into Perl, Tcl, etc. I still believe
a direct comparison is helpful. Also this test does not consider the
various ...to-C compilers available for Tcl, Perl, and Scheme.

The test is actually some very useful code in computer graphics. It is
a function to determine if a 2D point is inside a closed 2D
polygon. The polygon need not be convex. The original C version came
from the comp.graphics.algorithms FAQ. The function is called on 12
different points half in and half out (alternating) for 100000
iterations summing up how many points are inside - which comes to
12*1/2*100000 or 600000 if the code is correct - just in case you want
to write a version for a language I didn't get to. Thanks to everyone
who offered suggestions.

More happy computing!

MACHINE-TYPE:                   SPARCstation10 100MHz 128Mb RAM
SOFTWARE-VERSION:               SunOS 5.4 Generic_101945-27 sun4m

native compiler       time (sec)  lang                      html                  
---------------       ----------  ----                      ----
gcc -O3	(2.7.2)           6.0 	  C                 www.gnu.ai.mit.edu
gcc -O2 (2.7.2)           6.1 	  C
Franz Allegro Lisp 4.3    8.4 	  Common Lisp            www.franz.com
cc -O (SC3.0.1)           8.5 	  C
cc (SC3.0.1)             15.4 	  C

interpreter
-----------
Sun's Java 1.0.2        163.0     Java                www.javasoft.com
CINT (C/C++ interpr.)   530.0     C           hpsalo.cern.ch/root/Cint
Python1.4              1280.0     Python                www.python.org
Perl5.003              1710.0 	  Perl                    www.perl.com
Guile1.0               2060.0     Scheme            www.gnu.ai.mit.edu
Tcl8.0a2               2240.0 	  Tcl                sunscript.sun.com
Tcl7.4                24600.0     Tcl

CHANGES
-------
1. Perl version improved significantly.
2. Python version fixed (I left out an j=i statement) and improved
mostly stylistically. 
3. Minor change to Java version to make pnpoly method static.
4. Tcl version improved.

COMMENTS
--------
1. Unsuprisingly, native compiled code is much faster than interpreted.
2. Tcl 8.0 is much improved over Tcl 7.4.
3. Typed interpreted (Java & CINT) outperforms untyped interpreted.
4. Going into Tcl, Perl, Java, and Python almost cold - Python was
fastest to pick up on and debug; Tcl the slowest (but I used 7.4).
5. Java has no functions except methods on objects but with the static
keyword on methods at least you don't have to instantiate a dummy
class. Still irritating.
6. CINT 5.13 has a bug: replace  c = !c; with c ^= 1; to get around.

C-CINT-C-CINT-C-CINT-C-CINT-C-CINT-C-CINT-C-CINT-C-CINT-C-CINT-C-CINT-C-CINT

/*The code below is from Wm. Randolph Franklin <wrf@ecse.rpi.edu>
  with some minor modifications for speed.
  comp.graphics.algorithms FAQ 
  References:
    [Gems IV]  pp. 24-46
    [O'Rourke] pp. 233-238
    [Glassner:RayTracing] */

int pnpoly(int npol, double *xp, double *yp, double x, double y)
{
  int i, j, c = 0;
  for (i = 0, j = npol-1; i < npol; j = i++) {
    if ((((yp[i]<=y) && (y<yp[j])) ||
	 ((yp[j]<=y) && (y<yp[i]))) &&
	(x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))
      c = !c;
  }
  return c;
}

main() {
  int npol=20, count=0;
  double xp[20]= {0.0,1.0,1.0,0.0,0.0,1.0,-.5,-1.0,-1.0,-2.0,
		  -2.5,-2.0,-1.5,-.5,1.0,1.0,0.0,-.5,-1.0,-.5};
  double yp[20]= {0.0,0.0,1.0,1.0,2.0,3.0,2.0,3.0,0.0,-.5,
		  -1.0,-1.5,-2.0,-2.0,-1.5,-1.0,-.5,-1.0,-1.0,-.5};
  int i=0;
  for(i=0;i<100000;i++) {
    if (pnpoly(npol,xp,yp,0.5,0.5)) count++;
    if (pnpoly(npol,xp,yp,0.5,1.5)) count++;
    if (pnpoly(npol,xp,yp,-.5,1.5)) count++;
    if (pnpoly(npol,xp,yp,0.75,2.25)) count++;
    if (pnpoly(npol,xp,yp,0,2.01)) count++;
    if (pnpoly(npol,xp,yp,-.5,2.5)) count++;
    if (pnpoly(npol,xp,yp,-1.0,-.5)) count++;
    if (pnpoly(npol,xp,yp,-1.5,.5)) count++;
    if (pnpoly(npol,xp,yp,-2.25,-1.0)) count++;
    if (pnpoly(npol,xp,yp,0.5,-.25)) count++;
    if (pnpoly(npol,xp,yp,0.5,-1.25)) count++;
    if (pnpoly(npol,xp,yp,-.5,-2.5)) count++;
  }
  printf("count %d \n", count);
  return(0);
}

LISP-LISP-LISP-LISP-LISP-LISP-LISP-LISP-LISP-LISP-LISP-LISP-LISP-LISP-LISP-LISP-LISP-LISP

(defun pnpoly (npol xp yp x y)
  (declare (optimize (speed 3) (safety 0))
	   (fixnum npol)
	   (double-float x y)
	   (type (simple-array double-float (*)) xp yp))
  (let* ((c nil)
	 (j (1- npol)))
    (declare (fixnum j))
    (dotimes (i npol c)
      (declare (fixnum i))
      (if (and (or (and (<= (aref yp i) y) (< y (aref yp j)))
		   (and (<= (aref yp j) y) (< y (aref yp i))))
	       (< x (+ (aref xp i) (/ (* (- (aref xp j) (aref xp i)) (- y (aref yp i)))
				      (- (aref yp j) (aref yp i))))))
	  (setq c (not c)))
      (setq j i))))

(defun pt-poly-test ()
  (declare (optimize (speed 3) (safety 0)))
  (let ((npol 20)
	(count 0)
	(xp (make-array 20 :element-type 'double-float
			:initial-contents '(0.0d0 1.0d0 1.0d0 0.0d0 0.0d0 1.0d0 -.5d0 -1.0d0
					    -1.0d0 -2.0d0 -2.5d0 -2.0d0 -1.5d0 -.5d0 1.0d0
					    1.0d0 0.0d0 -.5d0 -1.0d0 -.5d0)))
	(yp (make-array 20 :element-type 'double-float
			:initial-contents '(0.0d0 0.0d0 1.0d0 1.0d0 2.0d0 3.0d0 2.0d0 3.0d0
					    0.0d0 -.5d0 -1.0d0 -1.5d0 -2.0d0 -2.0d0 -1.5d0
					    -1.0d0 -.5d0 -1.0d0 -1.0d0 -.5d0))))
    (declare (fixnum npol count)
	     (type (simple-array double-float (20)) xp yp))
    (dotimes (i 100000)
      (if (pnpoly npol xp yp 0.5d0 0.5d0) (incf count))
      (if (pnpoly npol xp yp 0.5d0 1.5d0) (incf count))
      (if (pnpoly npol xp yp -.5d0 1.5d0) (incf count))
      (if (pnpoly npol xp yp .75d0 2.25d0) (incf count))
      (if (pnpoly npol xp yp 0.0d0 2.01d0) (incf count))
      (if (pnpoly npol xp yp -.5d0 2.5d0) (incf count))
      (if (pnpoly npol xp yp -1.0d0 -.5d0) (incf count))
      (if (pnpoly npol xp yp -1.5d0 .5d0) (incf count))
      (if (pnpoly npol xp yp -2.25d0 -1.0d0) (incf count))
      (if (pnpoly npol xp yp .5d0 -.25d0) (incf count))
      (if (pnpoly npol xp yp .5d0 -1.25d0) (incf count))
      (if (pnpoly npol xp yp -.5d0 -2.5d0) (incf count)))
    (princ "Count ") (princ count)
    count))

TCL-TCL-TCL-TCL-TCL-TCL-TCL-TCL-TCL-TCL-TCL-TCL-TCL-TCL-TCL-TCL-TCL-TCL-TCL-TCL-TCL-TCL-TCL

proc pnpoly {npol xp yp x y} {
    set c 0
    set j [expr $npol-1]
    for {set i 0} {$i < $npol} {incr i 1} {
        if {(((([lindex $yp $i] <= $y) && ($y < [lindex $yp $j])) || 
	      (([lindex $yp $j] <= $y) && ($y < [lindex $yp $i])))
	     && ($x < (([lindex $xp $j] - [lindex $xp $i]) * ($y - [lindex $yp $i]) /
		       ([lindex $yp $j] - [lindex $yp $i]) + [lindex $xp $i])))} {
	    set c [expr !$c]
	}
	set j $i
    }
    return $c
}

proc pnpolytest {} {
    set count 0
    set npol 20
    set xp {0.0 1.0 1.0 0.0 0 1.0 -.5 -1.0 -1.0 -2.0 -2.5 -2.0 -1.5 -.5 1.0 1.0 0.0 -.5 -1.0 -.5}
    set yp {0.0 0.0 1.0 1.0 2.0 3.0 2.0 3.0 0.0 -.5 -1.0 -1.5 -2.0 -2.0 -1.5 -1.0 -.5 -1.0 -1.0 -.5}
    for {set i 0} {$i<100000} {incr i} {
	if {[pnpoly $npol $xp $yp 0.5 0.5]} {incr count}
	if {[pnpoly $npol $xp $yp 0.5 1.5]} {incr count}
	if {[pnpoly $npol $xp $yp -.5 1.5]} {incr count}
	if {[pnpoly $npol $xp $yp 0.75 2.25]} {incr count}
	if {[pnpoly $npol $xp $yp 0.0 2.01]} {incr count}
	if {[pnpoly $npol $xp $yp -.5 2.5]} {incr count}
	if {[pnpoly $npol $xp $yp -1.0 -.5]} {incr count}
	if {[pnpoly $npol $xp $yp -1.5 0.5]} {incr count}
	if {[pnpoly $npol $xp $yp -2.25 -1.0]} {incr count}
	if {[pnpoly $npol $xp $yp 0.5 -.25]} {incr count}
	if {[pnpoly $npol $xp $yp 0.5 -1.25]} {incr count}
	if {[pnpoly $npol $xp $yp -0.5 -2.5]} {incr count}
    }
    return $count
}

PERL-PERL-PERL-PERL-PERL-PERL-PERL-PERL-PERL-PERL-PERL-PERL-PERL-PERL-PERL-PERL-PERL-PERL

sub pnpoly {
    my($npol, $xxp, $yyp, $x, $y) = @_;
    my($j, $c, $i) = ($npol - 1, 0, 0);
    for ($i = 0; $i < $npol; $i++) {
	if (((($$yyp[$i] <= $y) && ($y < $$yyp[$j])) ||
	     (($$yyp[$j] <= $y) && ($y < $$yyp[$i]))) &&
	    ($x < (($$xxp[$j] - $$xxp[$i]) * 
		   ($y - $$yyp[$i]) /
		   ($$yyp[$j] - $$yyp[$i]) + $$xxp[$i]))) {
	    $c = !$c;}
	$j = $i;
    }
    $c;
}

sub polytest {
    local($npol, $count, @xp, @yp);
    $npol=20;
    $count=0;
    @xp = (0.0,1.0,1.0,0.0,0.0,1.0,-.5,-1.0,-1.0,-2.0,
	   -2.5,-2.0,-1.5,-.5,1.0,1.0,0.0,-.5,-1.0,-.5);
    @yp = (0.0,0.0,1.0,1.0,2.0,3.0,2.0,3.0,0.0,-.5,
	   -1.0,-1.5,-2.0,-2.0,-1.5,-1.0,-.5,-1.0,-1.0,-.5);
    for($ii = 0; $ii < 100000; $ii++) {
	if (pnpoly($npol,\@xp,\@yp,0.5,0.5)) {$count++};
	if (pnpoly($npol,\@xp,\@yp,0.5,1.5)) {$count++};
	if (pnpoly($npol,\@xp,\@yp,-.5,1.5)) {$count++};
	if (pnpoly($npol,\@xp,\@yp,0.75,2.25)) {$count++};
	if (pnpoly($npol,\@xp,\@yp,0,2.01)) {$count++};
	if (pnpoly($npol,\@xp,\@yp,-.5,2.5)) {$count++};
	if (pnpoly($npol,\@xp,\@yp,-1.0,-.5)) {$count++};
	if (pnpoly($npol,\@xp,\@yp,-1.5,.5)) {$count++};
	if (pnpoly($npol,\@xp,\@yp,-2.25,-1.0)) {$count++};
	if (pnpoly($npol,\@xp,\@yp,0.5,-.25)) {$count++};
	if (pnpoly($npol,\@xp,\@yp,0.5,-1.25)) {$count++};
	if (pnpoly($npol,\@xp,\@yp,-.5,-2.5)) {$count++};
    }
    print "\n count ", $count, "\n";
}

JAVA-JAVA-JAVA-JAVA-JAVA-JAVA-JAVA-JAVA-JAVA-JAVA-JAVA-JAVA-JAVA-JAVA-JAVA-JAVA-JAVA

public class Pnpoly {
  public static boolean pnpoly(int npol, double[] xp, double[] yp, double x, double y)
    {
      int i, j;
      boolean c = false;
      for (i = 0, j = npol-1; i < npol; j = i++) {
	if ((((yp[i]<=y) && (y<yp[j])) ||
	     ((yp[j]<=y) && (y<yp[i]))) &&
	    (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))
	  c = !c;
      }
      return c;
    }

  public static void main(String args[]) {
    int npol=20, count=0;
    double[] xp = {0.0,1.0,1.0,0.0,0.0,1.0,-.5,-1.0,-1.0,-2.0,-2.5,-2.0,-1.5,-.5,1.0,1.0,0.0,-.5,-1.0,-.5};
    double[] yp = {0.0,0.0,1.0,1.0,2.0,3.0,2.0,3.0,0.0,-.5,-1.0,-1.5,-2.0,-2.0,-1.5,-1.0,-.5,-1.0,-1.0,-.5};
    for(int i=0;i<100000;i++) {
      if (Pnpoly.pnpoly(npol,xp,yp,0.5,0.5)) count++;
      if (Pnpoly.pnpoly(npol,xp,yp,0.5,1.5)) count++;
      if (Pnpoly.pnpoly(npol,xp,yp,-.5,1.5)) count++;
      if (Pnpoly.pnpoly(npol,xp,yp,0.75,2.25)) count++;
      if (Pnpoly.pnpoly(npol,xp,yp,0,2.01)) count++;
      if (Pnpoly.pnpoly(npol,xp,yp,-.5,2.5)) count++;
      if (Pnpoly.pnpoly(npol,xp,yp,-1.0,-.5)) count++;
      if (Pnpoly.pnpoly(npol,xp,yp,-1.5,.5)) count++;
      if (Pnpoly.pnpoly(npol,xp,yp,-2.25,-1.0)) count++;
      if (Pnpoly.pnpoly(npol,xp,yp,0.5,-.25)) count++;
      if (Pnpoly.pnpoly(npol,xp,yp,0.5,-1.25)) count++;
      if (Pnpoly.pnpoly(npol,xp,yp,-.5,-2.5)) count++;
    }
    System.out.println("count " + count);
  }
}

PYTHON-PYTHON-PYTHON-PYTHON-PYTHON-PYTHON-PYTHON-PYTHON-PYTHON-PYTHON-PYTHON-PYTHON

def pnpoly(npol, xp, yp, x, y):
    c = 0
    j=npol-1
    for i in range(npol):
	if ((yp[i] <= y < yp[j] or yp[j] <= y < yp[i]) and
	    (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i])):
	    c = not c
	j = i
    return c

def pnpolytest():
    count=0
    npol=20
    xp= [0.0,1.0,1.0,0.0,0.0,1.0,-.5,-1.0,-1.0,-2.0,-2.5,-2.0,-1.5,-.5,1.0,1.0,0.0,-.5,-1.0,-.5]
    yp= [0.0,0.0,1.0,1.0,2.0,3.0,2.0,3.0,0.0,-.5,-1.0,-1.5,-2.0,-2.0,-1.5,-1.0,-.5,-1.0,-1.0,-.5]
    for i in range(10000):
	if (pnpoly(npol,xp,yp,0.5,0.5)): count=count+1
	if (pnpoly(npol,xp,yp,0.5,1.5)): count=count+1
	if (pnpoly(npol,xp,yp,-.5,1.5)): count=count+1
	if (pnpoly(npol,xp,yp,0.75,2.25)): count=count+1
	if (pnpoly(npol,xp,yp,0,2.01)): count=count+1
	if (pnpoly(npol,xp,yp,-.5,2.5)): count=count+1
	if (pnpoly(npol,xp,yp,-1.0,-.5)): count=count+1
	if (pnpoly(npol,xp,yp,-1.5,.5)): count=count+1
	if (pnpoly(npol,xp,yp,-2.25,-1.0)): count=count+1
	if (pnpoly(npol,xp,yp,0.5,-.25)): count=count+1
	if (pnpoly(npol,xp,yp,0.5,-1.25)): count=count+1
	if (pnpoly(npol,xp,yp,-.5,-2.5)): count=count+1
    print 'count ', count

GUILE-SCHEME-GUILE-SCHEME-GUILE-SCHEME-GUILE-SCHEME-GUILE-SCHEME-GUILE-SCHEME-GUILE-SCHEME

(define pt-in-poly
  (lambda (npol xp yp x y)
    (let ((c #f)
	  (j (- npol 1)))
      (do ((i 0 (+ i 1)))
	  ((= i npol) c)
	(if (and (or (and (<= (vector-ref yp i) y) (< y (vector-ref yp j)))
		     (and (<= (vector-ref yp j) y) (< y (vector-ref yp i))))
		 (< x (+ (vector-ref xp i)
			 (/ (* (- (vector-ref xp j) (vector-ref xp i)) (- y (vector-ref yp i)))
			    (- (vector-ref yp j) (vector-ref yp i))))))
	    (set! c (not c)))
	(set! j i))
      )))

(define pnpolytest
  (lambda ()
    (let ((npol 20)
	  (count 0)
	  (xp '#1(0.0 1.0 1.0 0.0 0.0 1.0 -.5 -1.0 -1.0 -2.0 -2.5 -2.0 -1.5 -.5 1.0 1.0 0.0 -.5 -1.0 -.5))
	  (yp '#1(0.0 0.0 1.0 1.0 2.0 3.0 2.0 3.0 0.0 -.5 -1.0 -1.5 -2.0 -2.0 -1.5 -1.0 -.5 -1.0 -1.0 -.5)))
      (do ((i 0 (+ i 1)))
	  ((= i 100000))
	(if (pt-in-poly npol xp yp 0.5 0.5) (set! count (+ count 1)))
	(if (pt-in-poly npol xp yp 0.5 1.5) (set! count (+ count 1)))
	(if (pt-in-poly npol xp yp -.5 1.5) (set! count (+ count 1)))
	(if (pt-in-poly npol xp yp .75 2.25) (set! count (+ count 1)))
	(if (pt-in-poly npol xp yp 0.0 2.01) (set! count (+ count 1)))
	(if (pt-in-poly npol xp yp -.5 2.5) (set! count (+ count 1)))
	(if (pt-in-poly npol xp yp -1.0 -.5) (set! count (+ count 1)))
	(if (pt-in-poly npol xp yp -1.5 .5) (set! count (+ count 1)))
	(if (pt-in-poly npol xp yp -2.25 -1.0) (set! count (+ count 1)))
	(if (pt-in-poly npol xp yp .5 -.25) (set! count (+ count 1)))
	(if (pt-in-poly npol xp yp .5 -1.25) (set! count (+ count 1)))
	(if (pt-in-poly npol xp yp -.5 -2.5) (set! count (+ count 1)))
	)
      (display "count ") (write count) (newline)
      count
      )))


-- 

John D. Watton 
Aluminum Company of America
Alcoa Technical Center
100 Technical Drive, Alcoa Center PA 15069

(412) 337-2165



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

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 474
*************************************

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