[6957] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 582 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 6 17:17:28 1997

Date: Fri, 6 Jun 97 14:00:25 -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           Fri, 6 Jun 1997     Volume: 8 Number: 582

Today's topics:
     Re: -----> replacing & symbol! <------- <Jan.Krynicky@st.mff.cuni.cz>
     ADVICE Sought: PGPERL Installation on Solaris2.5.1 and/ <adavid@netinfo.com.au>
     Calling Perl functions from C++ <mshpigel@platsol.com>
     Client scripts <michael.cameron@mci.com>
     converting HTML tables to delimited text? (Andrew Ryan)
     Displaying a Web Site Tree? (Rick Barkhouse)
     Re: find out no.of lines in open file (Tung-chiang Yang)
     help! CGI ignorant! <hogsauce@wwa.com>
     Re: help! CGI ignorant! <brooks-n-janet@worldnet.att.net>
     Re: HTML Output from Perl (A. Deckers)
     Re: inconsistent opendir behaviour in Perl for win32 <rootbeer@teleport.com>
     Re: inconsistent opendir behaviour in Perl for win32 (Simon Oosthoek)
     Installing Modules on NT (Does Net::NNTP work on NT?) <thuja@internauts.ca>
     Max files open != resource limit <wanda@io.com>
     Re: Output of shell script to html <rootbeer@teleport.com>
     Re: Package question <rootbeer@teleport.com>
     Re: Perl obfuscated contest (Faust Gertz)
     Perl Patterns for CGI <thuja@internauts.ca>
     PGPERL :- Solaris 2.5.1 (or HP/UX 9.04) - Binaries/Assi <adavid@netinfo.com.au>
     Re: Printing Prime Numbers <sibsib@hotmail.com>
     Re: Printing Prime Numbers (Steven Elliot Pav)
     Re: Printing Prime Numbers (Joel Graber)
     Re: Printing Prime Numbers (Craig Berry)
     read file while running <Joe.Kline@sdrc.com>
     Re: read file while running <sibsib@hotmail.com>
     use of quotes in here doc tag (Will Sexton)
     x operator <eglamkowski@mathematica-mpr.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Fri, 06 Jun 1997 21:20:38 -0700
From: Jan Krynicky <Jan.Krynicky@st.mff.cuni.cz>
To: Farshad Abasi <fabasi@unixg.ubc.ca>
Subject: Re: -----> replacing & symbol! <-------
Message-Id: <3398E196.49DB@st.mff.cuni.cz>

Farshad Abasi wrote:
> 
> Hello all,
> 
> I am trying to search s string for the & symbol and replace it with \&
> I did the following which did not work :-(
> 
> $title1 =~ s/'&'/'\&'/g;
> 
> I also tried
> 
> $title1 =~ s/&/\&/g;
> 
> and that also did not work.... any ideas??
> 
> --
>        -Farshad

#!/bin/perl
$x='agsh&ddd';

print "$x\n";

$x =~ s/&/\\&/g;

print "$x\n";

__END__

Hi, Jenda


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

Date: Fri, 06 Jun 1997 21:45:22 +1000
From: Anthony David <adavid@netinfo.com.au>
Subject: ADVICE Sought: PGPERL Installation on Solaris2.5.1 and/or HPUX 9.04
Message-Id: <3397F852.7E1F@netinfo.com.au>

Greetings All

After being inspired by Shishir Gundavarum that pgperl is the package
for them, our intrepid applicators have charged me with the mission
of installing it for them on one or both of the above systems.

I have successfully installed the pgplot libraries on both OSs
by using the binaries from the  pgplot server
http://astro.caltech.edu/~tjp/pgplot/ .
Pretty X graphics are displayed by the demo program.

The source of my current frustration has been installing the PGPPLOT
2.05 package.

Not having a Fortran Compiler on either machine, I have been stumbling
along
trying to install the f2c (makefile reader problem on Solaris) along
with what has 
been a torturous attempt at installing gcc cand g77(gcc is a prereq).

I'm sure I can amuse myself for hours following that path and I plan to
do so,
however, I would appreciate being pointed  in the direction of a binary
package
of pgperl for perl 5.003 on Solaris 2.5.1 (Ultra ) or HPUX 9.04
(hp-pa(1.1)?
9000 800/G70). Alternatively, if anyone has found some particularly
helpful
tips I would appreciate them sharing it with this group or, mailing me
directly
(careful - my address has been anti-SPAMMED). Any mail received will be 
summarised and posted to this group.

Regards

Anthony David
Systems Administrator


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

Date: Fri, 06 Jun 1997 14:26:30 -0400
From: Michael Shpigel <mshpigel@platsol.com>
Subject: Calling Perl functions from C++
Message-Id: <33985656.688ADC03@platsol.com>

Hello,

I am trying to call Perl function from C++
on NT using perl_call_pv function.

I have few questions:

1) Is there a header file I need to include into my
   C++ app or perhaps .lib file to link in?

2) if my perl function "fred" is in the file hello.pl,
   how should first parameter of the perl_call_pv look like.

Any help is highly appreciated.  
Thank you very much in advance.

Michael

P.S. You can send me reply directly at mshpigel@platsol.com


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

Date: Fri, 06 Jun 1997 19:03:28 +0000
From: Michael James Cameron <michael.cameron@mci.com>
Subject: Client scripts
Message-Id: <33985F00.B43@mci.com>

Can anyone send me scripts of any reasonably simple client software for
file transfers?

I want to write a tftp client (capable of a "get" for a binary file
only) but have had no success - has anyone got anything even vaguely
similar?

Any examples of anything using UDP, any simple (limited functionality)
ftp clients or references to books/journals/websites/listservers will be
most gratefully accepted!


Thanks in advance,

Michael

mailto:Michael.Cameron@MCI.com


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

Date: 6 Jun 1997 20:29:18 GMT
From: andryan@modesto (Andrew Ryan)
Subject: converting HTML tables to delimited text?
Message-Id: <5n9ruu$5p0@agate.berkeley.edu>


I'm wondering if anyone has a module or routine that converts HTML tables
into some sort of delimited text. The idea of writing one isn't incredibly
hard, but I can see that the actual implementation, dealing with
exceptions and such would be a pain. So before I consider this project I'd
like to know if anyone else has taken this on yet.

I've checked the CPAN (HTML::Format doesn't do tables as of v5.08),
DejaNews, FAQ, etc. and no one seems to have anything posted that does
this.

So, if anyone has ever done this, or even taken a stab at it or written a
table converter for a very basic type of table (which my tables are) and
has some source, I'd love to be able to take a look at it. 

Many thanks,
andrew


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

Date: Fri, 6 Jun 1997 17:10:30 GMT
From: rbarkhou@rc.gc.ca (Rick Barkhouse)
Subject: Displaying a Web Site Tree?
Message-Id: <EBD6DJ.4Jo@rc.gc.ca>

Does anyone know of a program or script (preferably in Perl) that I can 
use on our Unix web server to give a tree-like display of the web site?  
It would take an index file and recursively branch off with each local html 
file it finds referenced.

--
Rick Barkhouse <rbarkhou@rc.gc.ca>
Data Administration Specialist
Revenue Canada, Internet Services Division - IHID
Work: 613.952.0189


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

Date: Fri, 6 Jun 1997 19:57:50 GMT
From: tcyang@netcom.com (Tung-chiang Yang)
Subject: Re: find out no.of lines in open file
Message-Id: <tcyangEBDE4E.8GC@netcom.com>

This could consume a huge amount of memory if the file being counted is big.
I still prefer to use some counters like

   $count = 0; $count++ while (<COUNT>);

for files which could be big or I am not sure of its size.

=========================================
Craig Berry (cberry@cinenet.net) wrote:

: I'm surprised nobody has mentioned:

:   @lines      = <COUNT>;
:   $line_count = @lines;

: In a scalar context, a list evaluates to its entry count.

--
Tung-chiang Yang                       tcyang@netcom.com

soc.culture.taiwan, soc.culture.china (by SCC FAQ Team) FAQ's:
   http://www.iglou.com/tcyang/Taiwan_faq.shtml, China_faq.shtml


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

Date: Fri, 06 Jun 1997 14:20:01 +0000
From: Sam Fulton <hogsauce@wwa.com>
Subject: help! CGI ignorant!
Message-Id: <33981C91.5F9A@wwa.com>

howdy.

I'm doing web design for an advertising company, and one of their clients wants a deal 
whereby in order for a person visiting their site to get to certain places, they must first fill out 
a form for submission.  This form will ask for such info as e-mail addys, and stuff like that.

Despite my loud and frequent objections to such a thing being brought into existence, I have 
to do it anyway.

I have a couple questions... (I'm up on my HTML, but the whole CGI/Perl thing is way outta 
my league.)

a) is there a way to REQUIRE someone to fill out a form in order to gain access to other 
areas? I'm sure there is, but I don't know how to go about it.

b) is there a way to verify the supplied information to see if it's bogus or not?  Like, can it be 
made to check the supplied e-mail info to make sure it's an actual addy?

Any and all help is welcome.

Thanks in advance,
Jason

samfulton@hogsauce.com


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

Date: 6 Jun 1997 20:37:14 GMT
From: "Brooks Davis" <brooks-n-janet@worldnet.att.net>
Subject: Re: help! CGI ignorant!
Message-Id: <01bc72b9$7d494000$648593cf@Brooks.st.hmc.edu>

[CCed to poster]
Sam Fulton <hogsauce@wwa.com> wrote in article <33981C91.5F9A@wwa.com>...

First, the right group for this question is probably
comp.infosystems.www.authoring.cgi since this is not  really a perl
question.

> a) is there a way to REQUIRE someone to fill out a form in order to gain
access
> to other areas? I'm sure there is, but I don't know how to go about it.

Several.  You could give the user a password when the fill out the form
that would let them access the pages.  Another way (that I like better)
would be to give them a cookie when they fill out the form and then hide
all the pages behind a CGI script that requires the cookie to server the
pages.

> b) is there a way to verify the supplied information to see if it's bogus
or not?  Like, > can it be made to check the supplied e-mail info to make
sure it's an actual addy?

Not really. The best you can really do is apply huristics and hope they
work. For instance, you can use Tom's email address checker[1] to check
emil addresses, but there is no really way to make sure they are actually
valid.

[1] http://www.perl.com/perl/scripts/ckaddr


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

Date: 6 Jun 1997 18:51:41 GMT
From: I-hate-cyber-promo@man.ac.uk (A. Deckers)
Subject: Re: HTML Output from Perl
Message-Id: <slrn5pgn19.qbk.I-hate-cyber-promo@nessie.mcc.ac.uk>

In <3396c51a.2615177@news.wt.com.au>,
	Graham Daniell <gdaniell@wt.com.au> wrote:
>Hi,
>
>I am an absolute beginner with PERL, trying to learn it and discover
>how it works.  I have the book " Intriduction to CGI/Perl" by Brenner
>& Aoki.  In it they give an example of a Perl program as follows:
>---------------------------
>#!/usr/ucb/perl
>
>print "Content-type: text/html\n\n";
>
>print "<html>\n";
>print "<head>\n";
>print "<title>Hello World with Perl</title>\n;
>print "</head>\n";
>print "<body>\n";
>print "<h1>Hello World</h1>\n";
>print "</body>\n";
>print "</html>\n";
>------------------------

This would look _so_ much neater if they used a here document:

print <<HERE;
Content-Type: text/html

<html>
 ...
</html>
HERE

> I have typed this in as ptest.cgi, and done chmod 777 ptest.cgi on
                                         ^^^^^^^^^^^^^^
   That's a _really_ bad idea. 755 is more than enough.

>it.  My question is: ...
>How do I call this script from a HTML page in order to get it to
>return the "Howdy World" to the browser?

Sounds like you need to do some RTFMing:

<URL:http://www.perl.com/CPAN/doc/FAQs/cgi/idiots-guide.html>

Don't be offended by the document's name. It contains really usefull
advice.

BTW, this last question is not Perl-specific, so it is better addressed
to a group in the comp.infosystems.www.* hierarchy. Followups set
accordingly.

HTH,

Alain

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


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

Date: Fri, 6 Jun 1997 11:18:35 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Wm <wm_n00@tarrcity.demon.co.uk>
Subject: Re: inconsistent opendir behaviour in Perl for win32
Message-Id: <Pine.GSO.3.96.970606111719.21788i-100000@kelly.teleport.com>

On Fri, 6 Jun 1997, Wm wrote:

> Checking on 'c:/'
>   -d says true...
>   but opendir can't open it: No such file or directory

That's ready to go into a bug report. If your don't have perlbug, your
distribution should have some documentation on how and where to send the
program which exhibits the bug. Thanks! 

-- 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: 6 Jun 1997 18:22:52 GMT
From: s.oosthoek@student.utwente.nl (Simon Oosthoek)
Subject: Re: inconsistent opendir behaviour in Perl for win32
Message-Id: <5n9khs$8sg@pandora.cs.utwente.nl>

In a previous article Wm <wm_n00@tarrcity.demon.co.uk> says...
>>
>>Maybe it is. But let's try a test to be sure. Does the output of this make
>>any sense? Hope this helps!
>
>Hmmn.  I tried this using build 306 on Win95 (having changed D to C and
>getting rid of the ... after "Checking on '$dir'" as Win95 uses ... as
>two directories up the tree) and received the ff:

<snip same findings as mine for build 304>

>
>However it also appears to me that using .. and . from the top of a DOS-
>type directory may be misleading so I tried again with "tmp/" placed
>immediately after [Cc]:/ and rx'd:

why doesn't it test 'c:/tmp/'?
I bet that gives the same result as 'c:/'

it seems to be the '/' at the end that is causing the problem....

>Checking on 'c:/tmp'
>  -d says true...
>  and opendir can open it...
>  and it has 46 items in it.

<snip other items>

>The case of the drive letter does not appear to be significant but the
>working of opendir at root level and subdirectory level vs -d does
>change.  Whether or not this should be the case I am unable to say.

I believe it shouldn't be the case. All tests are in some way a directory:
d:   = current directory on drive d:
d:/  = root directory of drive d:
d:/. = root directory of drive d:

and

d:/tmp   = /tmp on d:
d:/tmp/  = /tmp on d:
d:/tmp/. = /tmp on d:

I have reported the bug to activeware, so hopefuly it will be fixed in a future 
version....

Thanks for the results!

Simon.




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

Date: Fri, 06 Jun 1997 16:19:42 -0400
From: Michael Iles <thuja@internauts.ca>
Subject: Installing Modules on NT (Does Net::NNTP work on NT?)
Message-Id: <339870DE.32E7@internauts.ca>

What is the proper procedure for installing modules on NT? (I'm running
ActiveWare's 5.003 port.) Is it enough to just copy the .pm files into
the proper directory?

Specifically, I was hoping to get Net::NNTP running, but I get the
following error,

d:\>perl
use Net::NNTP;
Can't find loadable object for module IO in @INC at d:\utils\perl5\
    lib/IO/Handle.pm line 229
BEGIN failed--compilation aborted at D:\utils\perl5\lib/IO/Socket.pm
    line 112.
BEGIN failed--compilation aborted at D:\utils\perl5\lib/Net/NNTP.pm
    line 11.
BEGIN failed--compilation aborted at - line 1.

I don't know anything about bootstrapping in Perl or the DynaLoader --
can I even expect this to work on NT?

Thanks,
Mike.

-- 
Michael Iles, michaeli@dra.com                  PGP Fingerprint:
sub perl_mind { for ( <LIFE> ) { breathe; } }    CB 51 3B 92 A7 25 FB 74
      Ceci n'est pas une .sig                    68 5A 2D 37 34 D5 39 5B


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

Date: 6 Jun 1997 19:06:36 GMT
From: Warren AND Amanda <wanda@io.com>
Subject: Max files open != resource limit
Message-Id: <5n9n3s$k52$1@nntp-2.io.com>
Keywords: getrlimit setrlimit fileno resource syscall

Perl Community,

I have observed that Perl never allows a program to "max out" on file
descriptors, as allowed by the process resource limits.  I run into this
limitation in a socket application, though the resource limitation problem
exists for any type of file descriptor, file or socket.

Consider my emperical observations on two platforms, both w/ perl5.004:

Platform: SunOS 4.1.4 (rlim_max=256) (config info at bottom of message)

FILE DESCRIPTOR     DESCRIPTORS
LIMIT (rlim_cur)    ALLOWED
================    ===========
1 - 16              rlim_cur
17 - 32             16
33 - rlim_max       (rlim_cur/2)

Platform: Solaris 2.5 (rlim_max=1024) (config info at bottom of message)

FILE DESCRIPTOR     DESCRIPTORS
LIMIT (rlim_cur)    ALLOWED
================    ===========
1 - 256             rlim_cur
257 - rlim_max      256

I tried looking for arbitrary limitations in the Perl source code, but
could not find any.  Can anyone explain why a Perl program cannot open
the number of files specified by the resource limit?  Especially under
SunOS, where the limitation seems "stuck" at 16 while the descriptor
limit grows from 17 to 32... then grows by 1/2 after that?

Here is a test program I used to measure the file resource limits:

----- FILE: limits.pl ----- CUT HERE -----
#!/usr/local/bin/perl -w

use IO::File;
require "sys/syscall.ph";
require "sys/resource.ph";

die ("Usage: \"$0 LIMIT\", where LIMIT = [ 1 - ",&RLIM_INFINITY," ] \n")
    unless $rlim_arbitrary = 0 + $ARGV[0];

STDERR->close; STDIN->close;
STDOUT->printf("FYI: SYS_getrlimit=%d SYS_setrlimit=%d RLIMIT_NOFILE=%d\n",
    &SYS_getrlimit, &SYS_setrlimit, &RLIMIT_NOFILE);

# Read the current limits
$struct_rlimit = pack('i2',0,0);
syscall(&SYS_getrlimit, &RLIMIT_NOFILE, $struct_rlimit);
($rlim_cur,$rlim_max) = unpack('i2', $struct_rlimit);
print "OLD limits: current=$rlim_cur max=$rlim_max\n";

# Set the new limits
$rlim_arbitrary = $rlim_max if $rlim_arbitrary > $rlim_max;
$struct_rlimit = pack('i2', $rlim_arbitrary, $rlim_max);
syscall(&SYS_setrlimit, &RLIMIT_NOFILE, $struct_rlimit);

# Read the new limits (don't trust that setting them really worked)
$struct_rlimit = pack('i2',0,0);
syscall(&SYS_getrlimit, &RLIMIT_NOFILE, $struct_rlimit);
($rlim_cur,$rlim_max) = unpack('i2', $struct_rlimit);
print "NEW limits: current=$rlim_cur max=$rlim_max\n";

%handle=();
$i=1;  # Start from 1, because we never closed STDOUT
$i++ while $handle{$i} = IO::File->new(">/dev/null");
print "Files opened (including STDOUT): $i\n";
__END__
----- FILE END ----- CUT HERE -----

Here is the output of "perl -e 'use Config; print Config->myconfig'" for
both platforms talked about in this posting:

Summary of my perl5 (5.0 patchlevel 4 subversion 0) configuration:
  Platform:
    osname=sunos, osvers=4.1.4, archname=sun4-sunos
    uname='sunos pezz 4.1.4 1 sun4m '
    hint=recommended, useposix=true, d_sigaction=define
    bincompat3=y useperlio= d_sfio=
  Compiler:
    cc='gcc', optimize='-O', gccversion=2.7.2
    cppflags='-I/usr/local/include'
    ccflags ='-I/usr/local/include'
    stdchar='unsigned char', d_stdstdio=define, usevfork=true
    voidflags=15, castflags=0, d_casti32=define, d_castneg=define
    intsize=4, alignbytes=8, usemymalloc=y, randbits=31
  Linker and Libraries:
    ld='ld', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /usr/ucblib
    libs=-ldbm -ldl -lm -lc -lposix
    libc=/lib/libc.so.1.9, so=so
    useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=, ccdlflags=' '
    cccdlflags='-fpic', lddlflags='-assert nodefinitions -L/usr/local/lib'

Summary of my perl5 (5.0 patchlevel 4 subversion 0) configuration:
  Platform:
    osname=solaris, osvers=2.5, archname=sun4-solaris
    uname='sunos fanti 5.5 generic sun4u '
    hint=recommended, useposix=true, d_sigaction=define
    bincompat3=y useperlio= d_sfio=
  Compiler:
    cc='gcc', optimize='-O', gccversion=2.7.2
    cppflags='-I/usr/local/include'
    ccflags ='-I/usr/local/include'
    stdchar='unsigned char', d_stdstdio=define, usevfork=false
    voidflags=15, castflags=0, d_casti32=define, d_castneg=define
    intsize=4, alignbytes=8, usemymalloc=y, randbits=15
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -ldl -lm -lc -lcrypt
    libc=/lib/libc.so, so=so
    useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=, ccdlflags=' '
    cccdlflags='-fpic', lddlflags='-G -L/usr/local/lib'

Cheers,
--
Warren_Hyde@email.sps.mot.com
This email contains at least 30% post-consumer recycled ideas.


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

Date: Fri, 6 Jun 1997 11:15:39 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Mai Yang [I]" <yangma@cig.mot.com>
Subject: Re: Output of shell script to html
Message-Id: <Pine.GSO.3.96.970606111508.21788h-100000@kelly.teleport.com>

On Fri, 6 Jun 1997, Mai Yang [I] wrote:

> I am trying to write a perl script which will run a shell script
> and return the output to a webpage. 

Sounds like a PATH problem. 

When you're having trouble with a CGI program in Perl, you should first
look at the please-don't-be-offended-by-the-name Idiot's Guide to
solving such problems. It's available on the perl.com web pages. Hope
this helps!

   http://www.perl.com/perl/
   http://www.perl.com/perl/faq/
   http://www.perl.com/perl/faq/idiots-guide.html

-- 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: Fri, 6 Jun 1997 11:25:08 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Bob Wood <wood@ziplink.net>
Subject: Re: Package question
Message-Id: <Pine.GSO.3.96.970606111848.21788j-100000@kelly.teleport.com>

On Fri, 6 Jun 1997, Bob Wood wrote:

> I have some code that uses the Date::Manip module from CPAN.  I've
> wrapped up my code as a module, and use it in several other scripts.  In
> one case, the script I want to include my module in already uses
> Date::Manip.  Unfortunately, the script initializes Date::Manip one way,
> and my module wants to initialize Date::Manip another way. 

As far as I know, there's no way to keep two sets of Date::Manip data in
memory. :-( 

This sounds like you'd benefit from working with the author on re-writing
Date::Manip to allow object oriented calls. It shouldn't be too hard, if
you've used objects before. 

Good luck!

-- 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: Fri, 06 Jun 1997 19:00:19 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Re: Perl obfuscated contest
Message-Id: <33995c8f.2613441@news.wwa.com>

On 6 Jun 1997 15:02:53 GMT, "CS" <cswanson@io.com> wrote:

>Can any kind soul tell me where the Perl obfuscation contest hangs out. Web
>site, email, news group, etc?

The only one I know about was the 0th Annual Obfuscated Perl Contest
which appeared in the second and third issues of The Perl Journal.
You can take a look at:

Obfuscated Perl Contest
http://orwant.www.media.mit.edu/tpj/contest-obfusc

Awards
http://orwant.www.media.mit.edu/tpj/contest-obfusc-writeup

Entries 
http://orwant.www.media.mit.edu/tpj/contest-obfusc-entries

Entries for that one were due by July 22, 1996 and I don't know of any
other contests in the works.  Perhaps Tom or Jon can fill us in.  Tom?
Jon?

Streben nach Wahrheit

Faust Gertz
Philosopher at Large

"You got the flavor!" - JSBX


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

Date: Fri, 06 Jun 1997 15:44:48 -0400
From: Michael Iles <thuja@internauts.ca>
Subject: Perl Patterns for CGI
Message-Id: <339868B0.4B58@internauts.ca>

(I've probably lost most of my hoped-for readership by mentioning the
three hated letters...)

I've been working in Perl for a while and am just starting to get into
CGI programming. CGI requires an interesting model as all output must be
buffered until after any processing that might fail.

It seems to me that the obvious 'pattern' one would employ is to buffer
all the output until the end, in case an error requires an error screen
to be displayed.

I've been working with the wonderful CGI module, and in my first few
attempts I've been doing things like,

    my @header = ( -pragma => 'no-cache' );
    ...
    push @header, 
        ( -cookie => "$cookie_name=$cookie;path=$server_path" )
        if ( $set_cookie );

and then later,

    print header( @header );

so I can conditionally build up the page according to my needs, and then
have one piece of code deliver the finished page at the end when I'm
sure that nothing has failed.

(As a side note, one of the things that has convinced me that Perl is
the One True Way is in the flexibility of its syntax -- I can have
methods that accept ordered parameters, or named parameters (as CGI.pm
does), and I can store the named parameters in an array as above... that
kind of flexibility is unheard-of in C++. It gives me a warm fuzzy
feeling inside :)

So, my question is this: is this a common approach? Are there
alternatives? Do any of the modules explicitly support buffering a page
in memory before displaying it?

Comments appreciated,
Mike.

-- 
Michael Iles, michaeli@dra.com                  PGP Fingerprint:
sub perl_mind { for ( <LIFE> ) { breathe; } }    CB 51 3B 92 A7 25 FB 74
      Ceci n'est pas une .sig                    68 5A 2D 37 34 D5 39 5B


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

Date: Fri, 06 Jun 1997 19:42:30 +1000
From: Anthony David <adavid@netinfo.com.au>
Subject: PGPERL :- Solaris 2.5.1 (or HP/UX 9.04) - Binaries/Assistance request
Message-Id: <3397DB86.239@netinfo.com.au>

Greetings All

After being inspired by Shishir Gundavarum that pgperl is the package
for them, our intrepid applicators have charged me with the mission
of installing it for them on one or both of the above systems.

I have successfully installed the pgplot libraries on both OSs
by using the binaries from the  pgplot server
http://astro.caltech.edu/~tjp/pgplot/ .
Pretty X graphics are displayed by the demo program.

The source of my current frustration has been installing the PGPPLOT
2.05 package.

Not having a Fortran Compiler on either machine, I have been stumbling
along
trying to install the f2c (makefile reader problem on Solaris) along
with what has 
been a torturous attempt at installing gcc cand g77(gcc is a prereq).

I'm sure I can amuse myself for hours following that path and I plan to
do so,
however, I would appreciate being pointed  in the direction of a binary
package
of pgperl for perl 5.003 on Solaris 2.5.1 (Ultra ) or HPUX 9.04
(hp-pa(1.1)?
9000 800/G70). Alternatively, if anyone has found some particularly
helpful
tips I would appreciate them sharing it with this group or, mailing me
directly
(careful - my address has been anti-SPAMMED). Any mail received will be 
summarised and posted to this group.

Regards

Anthony David
Systems Administrator


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

Date: Fri, 06 Jun 1997 15:25:58 -0400
From: Scott Blanksteen <sibsib@hotmail.com>
Subject: Re: Printing Prime Numbers
Message-Id: <33986446.E21D7917@hotmail.com>

Darryl Caldwell wrote:
> He was told "print out all the prime numbers between 1 and 50." Coming
> from a liberal arts background, I had to first find out what a prime
> number _is_, then I set to working it out in Perl.
> 
> The result is below. Essential it first prints out 1 since we know that
> it a prime number, then it discards even numbers. Next, it runs a 

1 is NOT a prime number.  (Prime numbers have exactly two factors.)

Brain-dead answer to a brain-dead question (by the interviewer, not 
Mr. Caldwell):

print "2 3 5 7 11 13 17 19 23 29 31 37 41 43 47\n";

Scott

-- 
Scott I. Blanksteen
sib (at) worldnet (dot) att (dot) net


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

Date: 6 Jun 1997 19:45:56 GMT
From: pav@LAS.alfred.edu (Steven Elliot Pav)
Subject: Re: Printing Prime Numbers
Message-Id: <slrn5pgcfe.172.pav@LAS.alfred.edu>

>He was told "print out all the prime numbers between 1 and 50." Coming
>from a liberal arts background, I had to first find out what a prime
>number _is_, then I set to working it out in Perl.
>
>The result is below. Essential it first prints out 1 since we know that
>it a prime number, then it discards even numbers. Next, it runs a series

go back and relearn what a prime is.  1 is _not_ a prime number.

>of tests on the remain odd numbers. If the variable $b holds a decimal

50 is small enough that

perl -e 'print q/2,3,5,7,11,13,17,19,23,29,31,37,41,43,47/'

is the simplest, but perhaps this is cheating, and a prospective
employer doesn't want you to do things so quickly.

here is an alternative, efficient prime generator:


#! /usr/bin/perl
 
my @primes;

sub divides_evenly { int($_[1]/$_[0]) == ($_[1]/$_[0]); }
sub square_root_limit {int(sqrt($_[0])); }

sub is_prime
{
	my $num = shift;
	my $sqrt_limit = &square_root_limit($num);
	my $i = 0;
	my $possible_divisor = $primes[$i++] || $sqrt_limit+1;
	while ($possible_divisor <= $sqrt_limit)
	{
		&divides_evenly($possible_divisor, $num) and return 0;
		$possible_divisor = $primes[$i++] || $sqrt_limit+1;
	}
	return 1;
}

for (1..24)         #only check odd numbers
{
	&is_prime(2*$_ + 1) and push(@primes, (2*$_ + 1));
}
 
unshift(@primes, 2);        #2 is prime;
  
print join(qq/\n/, @primes), qq/\n/;

exit;
__END__

this method finds the square root limit of the prospective prime, then
checks the primes up to that limit to see whether they divide the
prospective prime--there's no sense in checking every composite
number, since they are made of primes.

>
>
>Darryl Caldwell             Oikiasuchou School
>___________________________________________________
>The Practice Hall: http://www.eznet.com/bravo/ph/ph.html
>Myth & Martial Culture

hope this helps.



-- 
                                                                        
steven_y_e_pav                             a_kind_of_computer_using_guy
pav@las.alfred.edu                           http://las.alfred.edu/~pav
505.667.9080                                      p990/lanl/la,nm,87545
505.661.0622                         3000_trinity_dr/apt_64/la,nm,87544


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

Date: 06 Jun 1997 20:26:27 GMT
From: jgraber@daldd.sc.ti.com (Joel Graber)
Subject: Re: Printing Prime Numbers
Message-Id: <JGRABER.97Jun6152627@sun_7407>


In article <5n9fjc$p43$1@pepper.eznet.com> Darryl Caldwell <darrylc@eznet.com> writes:
>    ...   Coming
> from a liberal arts background, I had to first find out what a prime
> number _is_, then I set to working it out in Perl.
>
> The result is below. Essential it first prints out 1 since we know that
> it a prime number, then it discards even numbers. Next, it runs a series
> of tests on the remain odd numbers.   ...  I'm curious if
> there are more efficient approaches. I am really interested in algorithms
> -- one of my weaker areas. I wouldn't have been able to come up with
> anything on the spot. I would appreciate any comments. Thanks.

A prime number program was one of my first programming efforts also.

After removing the \n from your print statements, I get an output of
1 3 5 7 11 13 17 19 23 29 31 37 41 43 47

I thought '2' was a prime number....
($_ =~ /^1\b/)  should really be ($_ == 1) for a numeric test

if (($_ == 1) || ($_==2)) {  # checks for special case of 1 or 2

If you are going to use a special non looped case for 2,
then the foreach $test loop can start at 3.

Other ways of doing the integer/decimal check are
    next TRY if ($b != int($b));  # rather than  if $b =~ /\./
or  next TRY if ($_ % $test);  # use modulo remainder test

if ($b !~ /c/) {x} else {x;y}  can also be expressed as
y if ($b =~ /c/); x;

foreach $a (1..$n)  is fine and readable for small loops
but it creates an anonymous list, and create time of large
lists can be slow.
  for($a=1;$a<=$n;$a++)  will be better esp for large $n

For algorithm improvement:
 the foreach $test loop can stop at sqrt($_), rather than $_
 and only needs to check primes, or near primes.

Other prime number algorithm optimization methods I have seen
include "Sieve of Eurosthenes" (horribly manged spelling).
Although perl is not a great language for speed optimized
number crushing, the Sieve might be interesting to implement
with perl bit vectors.  The Sieve method says to use a vector
with a bit for every number.  (1..50) would be
(11111111111111111111111111111111111111111111111111)
Special case ==1 again, print it and clear it.
(01111111111111111111111111111111111111111111111111)
TRY:  repeat loop until done {
   Look for the next set bit(2), print it as prime,
   then increment through the remaining vector by 2's
   and clear all of them.
   #00000000011111111112222222222333333333344444444445
   #12345678901234567890123456789012345678901234567890
   (00101010101010101010101010101010101010101010101010)
}
The next loop finds 3, and remaining vector is this
   #00000000011111111112222222222333333333344444444445
   #12345678901234567890123456789012345678901234567890
   (00001010001010001010001010001010001010001010001010)
The next loop finds 5, and remaining vector is this
   #00000000011111111112222222222333333333344444444445
   #12345678901234567890123456789012345678901234567890
   (00000010001010001010001000001010000010001010001010)
etc.

Similar to the Sieve method, you could keep a list
of all the prime numbers you have found so far,
and only set $test to that list up to sqrt($_).
This helps to minimize the number of  $b!=int($b)
checks that need to be made. 

Another interesting idea is to special case 1,2,3,5,7
and then increment from 12 by 6, checking +/-1 unless /5$/
which takes care of checking for numbers divisible by 2,3,5
Here is a demonstration program of two methods.

#!/usr/local/bin/perl
print "1 2 3 5 7 "; # initial primes
@primes=(7);
MAIN: 
# ending range (99)could be off by as much as 6(?)
  for($i=12;$i<99;$i+=6) { #$i+/-1 aready checked for 2,3,
      &check_for_prime7($a) unless ($a=$i-1) =~ /5$/; # check modulo 5 too
      &check_for_primep($a) unless ($a=$i+1) =~ /5$/; 
  } # end main
print "\n"; # final newline
                                
sub check_for_prime7{
    $p = shift @_;          # get incoming argument to $p
    return unless ($p % 7);
    for ( $test=12; $test<=sqrt($p)+8; $test+=6 ) {
        $p=0, last unless ($p % ($test-1)); # clear and quit
        $p=0, last unless ($p % ($test+1)); # clear and quit
    }
    if ($p) { push @primes, $p; print "$p "}
} # end sub check_for_prime7

sub check_for_primep{
    $p = shift @_;     # get incoming argument to $p
    foreach $test (@primes) { # check only list of primes
        $p=0, last unless ($p % $test);} # clear and quit
    if ($p) { push @primes, $p; print "$p "}
} # end sub check_for_primep
#output
1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 

Maybe Randal, Tom, or others could express the foreach $test
loop as a grep or map.  Is there some way out of the loop
without using $p=0 as a marker for failure?  Is there some easy
way to only check @primes up to the sqrt of $p, without checking
inside each iteration of $test?

If your liberal arts background includes research skills
(mine doesn't particularly) you can probably find lots of
discussions, or even whole books on algorithms general or
prime.  I hope this isn't your homework....


Joel

 Condensed original version
 #!perl
 MAIN:
  foreach (1..50) { #grab main number from initial range
  if ($_ =~ /^1\b/) { print "$_\n";  next; }
  $a = $_ / 2;
  next MAIN if $a !~ /\./; #next if an even number
 TRY:
   foreach $test (2..$_) { #start sublevel testing on odd
     $b = $_ / $test;
     next TRY if $b =~ /\./; #next if matches a decimal
     if ($b !~ /^1\b/) { last TRY; #whole number is not $_
                } else { print "$_\n";
                         last TRY;   }
   } # end foreach $test
 } #end foreach $_



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

Date: 6 Jun 1997 20:25:39 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Printing Prime Numbers
Message-Id: <5n9ro3$csm$1@marina.cinenet.net>

Darryl Caldwell (darrylc@eznet.com) wrote:
: A friend told me about a software test he had to do at a job interview.
: He was told "print out all the prime numbers between 1 and 50." Coming
: from a liberal arts background, I had to first find out what a prime
: number _is_, then I set to working it out in Perl.
: 
: The result is below. Essential it first prints out 1 since we know that
: it a prime number,

Actually, 1 is not considered a prime, for reasons I've never entirely 
understood.  But my friend the math genius assures me it's true. :)

[remainder of original poster's algorithm description and explanation 
snipped]

Your approach seems to work, but strikes me as a bit complicated.  Here's 
a general program which takes a number as a command-line parm, and prints 
all primes less than or equal to that number.

  @primes = ();

  NUM: 
  for ($num = 2; $num <= $ARGV[0]; $num++) {
    foreach $prime (@primes) {
      $div = $num / $prime;

      next NUM if ($div == int($div));
    }

    print "$num\n";
    push @primes, $num;
  }

---------------------------------------------------------------------
   |   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: Fri, 06 Jun 1997 13:56:27 -0400
From: Joe Kline <Joe.Kline@sdrc.com>
Subject: read file while running
Message-Id: <33984F4A.237C@sdrc.com>

perl people,

while a script is running and writing to a file,
is it possible to read the contents of that file
without closing/opening that file repeatedly?

If I have to open/close repeately is there an
efficient method of doing it? (see code snippet)

hope this isn't too generic, just wondering if there
is a way to monitor my script every now and then
from another Xwindow or such since the script can
take a bit to finish its business.

Thanks,
joe
--

/================================\ insert favorite disclaimer\
| Joe Kline                      |        cute phrase\
| E-Mail: Joe.Kline@sdrc.com     |        JAPH
\================================/
open ($CALL,">calls") or die "Can't open calls: $!";
foreach (@call_list)
{
        if ( $_ ne $old_val )
        {
                print $CALL "$_\n";
                $old_val = $_;
        }
}
close ($CALL);


This is perl, version 5.003 with EMBED
        built under irix at Oct 13 1996 08:23:53
        + suidperl security patch

Copyright 1987-1996, Larry Wall


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

Date: Fri, 06 Jun 1997 15:28:05 -0400
From: Scott Blanksteen <sibsib@hotmail.com>
Subject: Re: read file while running
Message-Id: <339864C5.1A4ED36A@hotmail.com>

Joe Kline wrote:
> while a script is running and writing to a file,
> is it possible to read the contents of that file
> without closing/opening that file repeatedly?

tail -f

Scott

-- 
Scott I. Blanksteen
sib (at) worldnet (dot) att (dot) net


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

Date: 6 Jun 1997 17:15:48 GMT
From: sextw@ils.unc.edu (Will Sexton)
Subject: use of quotes in here doc tag
Message-Id: <5n9gk4$5t3$1@fddinewz.oit.unc.edu>

I posted a question a few days ago about using here documents.  I got a 
lot of responses, for which I am grateful, but many of them include what 
I think is a misconception.  Namely, quotation marks around a the 
opening tag of the here-doc do not adversely affect the compilation of 
the program.  Rather, they force perl to treat the string in the 
here-doc as it would any string enclosed in quotes.  

For example:

	$blah = "blah";

	print <<'EOF';
	blah
	$blah
EOF
;

Prints

	blah
	$blah


Whereas:

	$blah = "blah";

	print <<"EOF";
	blah
	$blah
EOF
;

Prints

	blah
	blah


Just my $.02 worth.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Will Sexton                     wise2@mindspring.com
UNC-CH/Info Sci                 sextw@ils.unc.edu



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

Date: Fri, 06 Jun 1997 13:55:15 -0400
From: the count <eglamkowski@mathematica-mpr.com>
Subject: x operator
Message-Id: <33984F03.32E3@mathematica-mpr.com>

I have an array I want to initialize, and was curious if the 
following syntax was valid:

@current_disp_table = ( 32, (-1) x 19, 19..31, (-1) x 7 ); 

which I want to be a 40 element array of integers.
Or am I misunderstanding the x operator here?


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

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

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