[7139] in Perl-Users-Digest
Perl-Users Digest, Issue: 765 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 24 04:08:11 1997
Date: Thu, 24 Jul 97 01:02:11 -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 Thu, 24 Jul 1997 Volume: 8 Number: 765
Today's topics:
Perl - shell - Perl <jrajesh@lucent.com>
Re: Perl - shell - Perl <rootbeer@teleport.com>
Perl for Informix (Wei Tang)
Re: Perl Headers on Win NT (Bevan Broun)
Perl man pages on Solaris? (Trey Valenta)
Re: PLEASE HELP I NEED TO FIND THE PERL program QUICKLY <rootbeer@teleport.com>
Re: Please Help: Pattern Matching (daniel abrams)
Re: process handling (Matthew H. Gerlach)
Re: prototyping subroutines...not working <rootbeer@teleport.com>
Re: Q: e other thing I have to do iefficient way to use <sfairey@adc.metrica.co.uk>
Q: empty elements in arrays <Uwe.Lammers@astro.estec.esa.nl>
Re: Q: empty elements in arrays <sfairey@adc.metrica.co.uk>
Q: passing array to xsub? <lemur1@mindspring.com>
Re: Question: About strings, replacements and collapsin <rootbeer@teleport.com>
Re: Question: About strings, replacements and collapsin (Tad McClellan)
Re: read last line without reading previous lines, how? <sibsib@hotmail.com>
Re: Regex: Email address format (Matthew D. Healy)
Re: regexp problems:( <usenet-tag@qz.little-neck.ny.us>
Re: RFC: prop. for overloading 'next' keyword (Jason E Holt)
Sample TCP-server not working ... (Robert Sturrock)
simple? question <upsetter@zip1.ziplink.net>
Some problem! <nick@alekto.co.il>
Re: Some problem! <rootbeer@teleport.com>
Re: Sorting <merlyn@stonehenge.com>
Specifying where to look for modules first (Jason Bodnar)
Re: Sprite Database (Faust Gertz)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 23 Jul 1997 08:37:55 -0600
From: Jasper <jrajesh@lucent.com>
To: jrajesh@lucent.com
Subject: Perl - shell - Perl
Message-Id: <869603725.30032@dejanews.com>
Hi
I just started coding in Perl and I want to know how to get a value
back from a shell if I'm executing a shell from perl.
For example, if I were to write completely in shell script, I would
write
no_of_rec=`isql <<.
select @a=count(*) from tableA
print @a
.
`
How would I do this in Perl ? I want the value of no_of_rec ??
Any help would be greatly appreciated !
Thanks.
- Jasper.
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Wed, 23 Jul 1997 08:49:28 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Jasper <jrajesh@lucent.com>
Subject: Re: Perl - shell - Perl
Message-Id: <Pine.GSO.3.96.970723084731.14902O-100000@kelly.teleport.com>
On Wed, 23 Jul 1997, Jasper wrote:
> I just started coding in Perl and I want to know how to get a value
> back from a shell if I'm executing a shell from perl.
If you mean that you want the value of an environment variable, use %ENV
(documented in perlvar(1)). If you mean that you want a shell script which
you run to return some value to you, you may want qx//, documented in
perlop(1). Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 21 Jul 1997 01:27:20 GMT
From: wtang@cs.ualberta.ca (Wei Tang)
Subject: Perl for Informix
Message-Id: <5qudto$8al$1@scapa.cs.ualberta.ca>
Hi, there:
Is there any facility of Perl to access Informix database like Oraperl
for Oracle database?
Thanks.
------------------------------
Date: Tue, 22 Jul 1997 02:56:16 GMT
From: bevan.broun@health.wa.gov.au (Bevan Broun)
Subject: Re: Perl Headers on Win NT
Message-Id: <33d420f2.1022135142@news.bs.wa.gov.au>
On 16 Jul 1997 15:27:31 GMT, peak@ulc199.residence.gatech.edu (Jason
Peak) wrote:
>
>
>I'm trying to get an NT server to run some perl scripts for me.
>I've discovered that I have to make them .bat files and somehow
>call the perl.exe with the .bat file.
>
>Does anyone know how to do this? I've tried giving the
>c:\perl5\perl.exe test.bat in both a .bat and a .pl file.
>with no avail. Also, I've tried calling on a perl.exe with a
>.pl file and stil get server errors.
>
>Any help is greatly appreciated.
>
>Jason Peak
>peak@ulc199.residence.gatech.edu
>
I do not need to do any of this now 'cause I have
Perl for Win32 Build 306 - Built 17:50:28 Apr 10 1997
The association of .pl with perl was made during installation.
Bevan
------------------------------
Date: 22 Jul 1997 23:55:01 GMT
From: trey@zipcon.net (Trey Valenta)
Subject: Perl man pages on Solaris?
Message-Id: <869615718.866026@ran.zipcon.net>
Can anyone tell me the solution to getting perl manpages to properly
work under Solaris? I find no mention of this in any FAQ but it seems
that it isn't just me who wants to know. As it is, I can't get any of
the perl modules' man pages to be properly parsed and they all get
inserted improperly into the windex file.
Anyone?
Thanks,
trey
--
Trey Valenta trey@zipcon.net Seattle, WA
------------------------------
Date: Wed, 23 Jul 1997 08:32:24 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: george <george@elv.enic.fr>
Subject: Re: PLEASE HELP I NEED TO FIND THE PERL program QUICKLY
Message-Id: <Pine.GSO.3.96.970723083054.14902H-100000@kelly.teleport.com>
On Wed, 23 Jul 1997, george wrote:
> PLEASE HELP I NEED TO FIND THE PERL LANGAGE QUICKLY
Then you shouldn't use Usenet. You should use a search engine. But if
this is quick enough, maybe you want this? Hope this helps!
http://www.perl.org/
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 23 Jul 1997 14:45:53 GMT
From: dabrams@mathcs.emory.edu (daniel abrams)
Subject: Re: Please Help: Pattern Matching
Message-Id: <5r55f1$68h$1@cssun.mathcs.emory.edu>
After getting away from the computer for a bit, clarity set in.
After doing the substitution, I was stuffing the result in
a file by redirecting `echo`.
Of course, throwing " into this probably messed things up. I'm not
sure why it shows up in some cases and not in others, though.
When I get back to work, I'll test this theory. Thanks for the
suggestions and post.
Sorry if I led anyone astray.
Daniel
------------------------------
Date: Wed, 23 Jul 1997 14:14:51 GMT
From: gerlach@netcom.com (Matthew H. Gerlach)
Subject: Re: process handling
Message-Id: <gerlachEDrzKr.Mro@netcom.com>
If you know the process id of the process in question, just use the
kill function to test if it is alive.
Matthew
In article <5r04av$sor@bali.seg.wj.com> alan@wj.com writes:
> I want to test if a process has died, and restart it if it has.
> A simple "ps ax | grep process" and restart if missing.
>
> The script below works, but what's a "better" method ?
>
> open (PROC, "ps -ax 2>&1 |") or die "cannot fork $!";
> while (<PROC>) { push(@ps,$_); }
> close(PROC);
> # @ps array built, see if squid's in there
> @sq = grep (/squid/,@ps);
> system ('/u1/squid/bin/squid &') if ! @sq;
>
> I've read perlfaq8 to no avail.
>
> alan
>--
>alan@wj.com
------------------------------
Date: Tue, 22 Jul 1997 16:20:14 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Terry Michael Fletcher - PCD ~ <tfletche@pcocd2.intel.com>
Subject: Re: prototyping subroutines...not working
Message-Id: <Pine.GSO.3.96.970722161637.28607A-100000@kelly.teleport.com>
On 22 Jul 1997, Terry Michael Fletcher - PCD ~ wrote:
> : I have been trying to get a subroutine call to work without giving it an
> : empty argument, namely, to do this:
> oops.... i have to correct myself here. the sub declaration is made in a
> library that is required at the beginning of the perl file in question.
That's the problem. Perl is compiling your main program, but it doesn't
see the prototype until the require is done, at runtime. The compiler
needs to see the prototype during the compile phase.
Here's one solution: Wrap the require in a BEGIN block, to make it happen
during the compile phase.
BEGIN {
require "whatever.pl"; # Get the prototype early
}
whatever; # Is now prototyped
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 23 Jul 1997 14:56:34 +0100
From: Simon Fairey <sfairey@adc.metrica.co.uk>
To: Klaus Foerster <klausf@mucsun.sps.mot.com>
Subject: Re: Q: e other thing I have to do iefficient way to use subarrays
Message-Id: <33D60D90.10A85149@adc.metrica.co.uk>
Klaus Foerster wrote:
> Hi folks,
>
> The camel book (perl 4) says its more efficient to use
>
> foreach (@array){
> PROCESS $_;
> }
>
> than doing
>
> for($i=0;$i<@array;$i++){
> PROCESS($array[$i]);
> }
>
> I have an array containing about 1 million text lines (The machine has
>
> enough RAM for that).
>
> I have to process certain subsections of this array.
>
> Is there a faster way to process sections of an array
> (example: elements 200,000 - 800,00)
If you have the memory you could take a copy of those elements, i.e.
@array_slice = @array_main[200000..800000];
>
>
> or do I have to do this with a for loop.
>
> The other thing i have to do is
> searching a set of about 20 regular expressions within a
> sub array. Again I'd like to know the fastest way.
>
For a better explanation than I could give look at the following section
in the Perl FAQ"How do I efficiently match many regular expressions at
once?"
> The set of regular expressions is stored in an array @expr and can
> change during runtime.
>
> Any help is appreciated.
>
No problem.
> ThanX in advance
>
Its better to thank in arrears :-)
> bye
> Klaus
Simon
------------------------------
Date: Wed, 23 Jul 1997 14:08:36 +0200
From: Uwe Lammers <Uwe.Lammers@astro.estec.esa.nl>
Subject: Q: empty elements in arrays
Message-Id: <33D5F444.C26@astro.estec.esa.nl>
Hi,
looking for the most efficient way to determine whether a string array
contains empty entries, i.e.,
('1', '2', '3') -> no
('1', '2', '', '3') -> yes
one ugly, non-fail-safe way would be
if (join("@", @list) !~ /\@\@|^\@|\@$/) {
print "no ";
}
print "empty elements\n";
Alternative suggestions?
Cheers
Uwe (ulammers@astro.estec.esa.nl)
------------------------------
Date: Wed, 23 Jul 1997 15:07:53 +0100
From: Simon Fairey <sfairey@adc.metrica.co.uk>
To: Uwe Lammers <Uwe.Lammers@astro.estec.esa.nl>
Subject: Re: Q: empty elements in arrays
Message-Id: <33D61037.391192A9@adc.metrica.co.uk>
Uwe Lammers wrote:
> Hi,
>
> looking for the most efficient way to determine whether a string array
>
> contains empty entries, i.e.,
>
> ('1', '2', '3') -> no
> ('1', '2', '', '3') -> yes
>
> one ugly, non-fail-safe way would be
>
> if (join("@", @list) !~ /\@\@|^\@|\@$/) {
> print "no ";
> }
> print "empty elements\n";
>
> Alternative suggestions?
>
> Cheers
> Uwe (ulammers@astro.estec.esa.nl)
How about:
grep( !length($_), @list ) and print "empty elements\n";
Simon
NB: Use of length is to prevent it evaluating to TRUE for a value of
'0'.
------------------------------
Date: Tue, 22 Jul 1997 23:38:38 -0600
From: Mike Fletcher <lemur1@mindspring.com>
Subject: Q: passing array to xsub?
Message-Id: <869631656.23094@dejanews.com>
I'm just starting to play with writing xsubs and I'm having
a problem figuring out the best (or at least most used :)
method of handling an array as an argument. The func I'm
trying to hook to is prototyped (it's the Expect C library,
for the curious):
int exp_spawnv( char *file, char *argv[ ] )
I'm looking to prototype this as $@ in perl so that it would
be called:
@args = qw( /bin/cat a b c );
exp_spawnv '/bin/cat', @args;
I've tried defining the xsub with
int
exp_spawnv( file, ... )
char* file;
and with
int
exp_spawnv( file, argv )
char* file;
AV* argv;
Neither of these seem to work correctly. I'd appreciate it if someone
could point me to the correct part of perlxs or perlguts, or a pointer
to an existing module that has a similar func in one of its .xs files.
Thanks in advance.
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Tue, 22 Jul 1997 17:10:37 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: dcd@k12-dev.arc.nasa.gov
Subject: Re: Question: About strings, replacements and collapsing white space
Message-Id: <Pine.GSO.3.96.970722164914.28607J-100000@kelly.teleport.com>
On Tue, 22 Jul 1997 dcd@k12-dev.arc.nasa.gov wrote:
> I have a string ($data) that contains the contents of a text file, as
> well as a search string ($searchString) that I want to replace with
> $text in all instances (ie globally). The problem arises that, as my
> search string could be rather lengthy, and not spaced the same as when
> it appears in $data, a straight $data =~ s/$searchString/$text/g won't
> work.
The trick is to make your search string use a regular expression,
something like this.
$searchString = q{\bthis\s+is\s+a\s+test\b};
If your string is coming from anything as unpredictable as a human being,
you'll want to check it to make sure that, for example, it doesn't have
unbalanced parentheses. If your human can't be trained to write a regular
expression in the first place, and most humans can't, you may need to
modify their given string to make one, with statements like this.
$searchString =~ s/([^\w\s])/\\$1/g; # Fix metachars (Can't \Q)
$searchString =~ s/\s+/\\s+/g; # Change whitespace to \s+
$searchString =~ s/^(\w)/\\b$1/; # \b at beginning
$searchString =~ s/(\w)$/$1\\b/; # \b at end
And you'll want to read the docs about what /o does. Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 22 Jul 1997 18:35:25 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Question: About strings, replacements and collapsing white space
Message-Id: <t3g3r5.qma.ln@localhost>
dcd@k12-dev.arc.nasa.gov wrote:
: I'm relatively new to Perl and have a somewhat complicated question
: (hopefully just complicated to explain and not to solve :) )....
I think your hope is justified ;-)
: I have a string ($data) that contains the contents of a text file, as
: well as a search string ($searchString) that I want to replace with
: $text in all instances (ie globally). The problem arises that, as my
: search string could be rather lengthy, and not spaced the same as when
: it appears in $data, a straight $data =~ s/$searchString/$text/g won't
: work. For example....
: if my search string is..
: 'this is a search string'
: ...and I want it to match...
: '
: this is
: a search
: string'
: ....it won't do it unless I collapse the white space. So that's what
^^^^^^^^^^^^^^^^^^
There are two parts to pattern matching.
The string to be matched against ($data), and
the pattern to try and match ($searchString).
As you point out below, modifying $data won't get you where you want
to go. Consider changing $searchString instead (see below)
: I did, with ($copy = $data) =~ s/\s+/ /g; If I collapse both $data
: and $searchString this way, they match up just fine and I can make a
: straight replacement using a s///; But here's the real problem
: (finally). Since I plan to write $data back to a file, I don't want
: it's white space to be collapsed. I need some way to un-collapse the
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Not if you can find a way to match without doing any collapsing (see below)
: white space after I've made the replacements, or find an entirely new
: way to do it.
: If you've been patient enough to read through all that I thank you,
: and would greatly appreciate any help you could give me.
Hows this?
--------------------------
#! /usr/bin/perl -w
$data = 'this part does
not match
but
this is
a search
string some more text that does not
match this is
a search
string with some tabs in it
';
$text = 'ReplacementValue';
$searchString = 'this is a search string';
$searchString =~ s/\s+/(\\s+)/g; # convert one or more spaces into
# a regex that matches one or
# more spaces.
print "search '$searchString'\n\n"; # see that? Slick huh ;-)
$data =~ s/$searchString/$text/g;
print "$data\n";
--------------------------
: -Thanks a lot
You are welcome in equal measure ;-)
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Wed, 23 Jul 1997 15:09:25 -0400
From: Scott Blanksteen <sibsib@hotmail.com>
Subject: Re: read last line without reading previous lines, how?
Message-Id: <33D656E5.338B6389@hotmail.com>
Jeff Wilson wrote:
>
> Try ...
>
> open(TXT,"<textfile");
Don't forget to check the return value of open...
> @fred=<TXT>;
But this reads *all* the lines in textfile...
> print @fred[$#fred],"\n";
>
> : |> I wonder how to reading the last line of a text file, without
> going through
> : |> the previous lines. Thanks.
Scott
--
Scott I. Blanksteen
sib (at) worldnet (dot) att (dot) net
------------------------------
Date: Wed, 23 Jul 1997 11:11:29 -0500
From: Matthew.Healy@yale.edu (Matthew D. Healy)
Subject: Re: Regex: Email address format
Message-Id: <Matthew.Healy-2307971111290001@pudding.med.yale.edu>
The nearly-definitive answer to this is found in Jeff Friedl's book
{Mastering Regular Expressions}, published by O'Reilly. It is a real
MONSTER of a regular expression -- over 5000 characters long -- and
even then it will NOT cover all possible cases because regexes are
inherently incapable of doing so. The problem comes with nested
parenthetical comments -- regexes CANNOT balance parens to any
arbitrary number of levels -- so Friedl's example works for no more
than two levels of nesting.
In practice, you will find rather few RFC-compliant addresses that
Friedl's expression won't match in the real world. Contrived examples
that break his regex will usually break lots of mailers out there
anyway!
And, while I am sure _you_ know this, for the benefit of those who
do not I will add that any regex can ONLY verify the syntactical
correctness of an email address. Verifying that it actually WORKS
is in general not possible. Sometimes you can telnet to their SMTP
host and use EXPN or VRFY to check. Sometimes you can finger them.
Sometimes you can find an IDENTD or something. And in any case,
there would be nothing to stop me from, say, creating an account on
one of my systems just long enough for you to finger it and then
deleting it.
Sometimes you cannot. There are many different email systems out
there, and most of them now have some kind of gateway to the larger
Internet, but often these gateways will not provide any means for
outsiders to verify an address. Among other considerations, many
companies intentionally block directory-type queries from outside for
security reasons. There are just too many types of aliases, gateways,
forwarders, aliases, listservers, firewalls, etc., etc. out there for
any generalized method of verification to work.
And in any case, even if there were a means of verifying that a given
address can in fact receive mail, that would still not prove that the
person entering the address into your web form (the most common context
for this question these days) in fact is the user of the address. If
I tell you my email address is, say, President@Whitehouse.gov, how do
you know that I am not in fact President Clinton?
--------
Matthew.Healy@yale.edu http://ycmi.med.yale.edu/~healy/
As of 09 Jul 1997, only 905 days until Y2K....
Any person with a phone line can become a town crier with a voice
that resonates farther than it could from any soapbox.
--The US Supreme Court, overturning the Communications Decency Act
------------------------------
Date: 23 Jul 1997 19:31:47 GMT
From: Eli the Bearded <usenet-tag@qz.little-neck.ny.us>
Subject: Re: regexp problems:(
Message-Id: <eli$9707231516@qz.little-neck.ny.us>
Chris Schleicher <chrissch@cs.uoregon.edu> wrote:
> $foo =~ s/<(.+?)>/$1/g;
Dumb.
$foo =~ s/<([^>]+)>/$1/g;
Is faster, more portable, and less likely to break.
".*?c" for single char 'c's is always inferior to "[^c]*c".
Elijah
------
has fallen behind on his c.l.p.m reading
------------------------------
Date: 23 Jul 1997 21:17:20 GMT
From: holt@puree.cs.byu.edu (Jason E Holt)
Subject: Re: RFC: prop. for overloading 'next' keyword
Message-Id: <5r5sd0$eoh@hamblin.math.byu.edu>
Jeremy D. Impson (jdimpson@newstand.syr.edu) wrote:
[...]
: I've been doing a lot of coding that reads in stanzas into data
: structures lately.
: When I say 'stanza', I mean stuff like this:
: keyword0:
: info0 relative to keyword0
: info1 relative to keyword0
: info2 relative to keyword0
: keyword1:
: info0 relative to keyword1
[...]
Another way to do it is as follows:
@stanza = ();
$current_keyword = undef; # A little silly
while(<>) {
if(/^keyword0/) {
# Handle current contents of @stanza as members of
# a $current_keyword stanza,
# unless current_keyword == undef, in which case we're
# beginning the first stanza
&dealwith($current_keyword, @stanza)
if defined($current_keyword);
@stanza = ();
$current_keyword = "keyword0";
} elsif(/^keyword1/) {
# Ditto for keyword 1
} elsif(/^\s+/) {
push @stanza $_;
} else {
die("$_Invalid line ");
}
}
-J
------------------------------
Date: 21 Jul 1997 04:28:21 GMT
From: rns@ariel.ucs.unimelb.EDU.AU (Robert Sturrock)
Subject: Sample TCP-server not working ...
Message-Id: <5quoh5$f2k$1@izvestia.its.unimelb.edu.au>
Hi all.
I'm having some difficulty getting the (multi-threaded) TCP server
that's presented in the Perl book working properly. I'm running Perl
version 5.004_01 under Digital Unix 3.2. There appears to be a problem
with getting the child process's filehandles (ie. STDOUT) to do the
right thing.
When a new connection arrives, the server fork()s and then the child
does:
open(STDIN, "<&Client") || die "can't dup client to stdin";
open(STDOUT, ">&Client") || die "can't dup client to stdout";
The child then does:
spawn sub {
print "Hello there, $name, it's now ", scalar localtime, "\n";
exec '/usr/games/fortune'
or confess "can't exec fortune: $!";
};
The client receives the `fortune' output, but does not receive the
`print' output, like this:
granville$ telnet server 2346
Trying 128.250.99.99...
Connected to server.its.unimelb.edu.au.
Escape character is '^]'.
Do you have lysdexia?
I can't seem to get anything to go to STDOUT (ie. the socket), unless
it's part of an `exec'. Does anyone have any ideas what the problem
may be?
Below is the full source to the server. It's taken from the book, but
I actually just cut it straight from the `perlipc' manpage ...
TIA.
/r.
#!/usr/local/bin/perl -w
require 5.002;
use strict;
BEGIN { $ENV{PATH} = '/usr/ucb:/bin' }
use Socket;
use Carp;
sub spawn; # forward declaration
sub logmsg { print "$0 $$: @_ at ", scalar localtime, "\n" }
my $port = shift || 2346;
my $proto = getprotobyname('tcp');
$port = $1 if $port =~ /(\d+)/; # untaint port number
socket(Server, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
setsockopt(Server, SOL_SOCKET, SO_REUSEADDR,
pack("l", 1)) || die "setsockopt: $!";
bind(Server, sockaddr_in($port, INADDR_ANY)) || die "bind: $!";
listen(Server,SOMAXCONN) || die "listen: $!";
logmsg "server started on port $port";
my $waitedpid = 0;
my $paddr;
sub REAPER {
$waitedpid = wait;
$SIG{CHLD} = \&REAPER; # loathe sysV
logmsg "reaped $waitedpid" . ($? ? " with exit $?" : '');
}
$SIG{CHLD} = \&REAPER;
for ( $waitedpid = 0;
($paddr = accept(Client,Server)) || $waitedpid;
$waitedpid = 0, close Client)
{
next if $waitedpid and not $paddr;
my($port,$iaddr) = sockaddr_in($paddr);
my $name = gethostbyaddr($iaddr,AF_INET);
logmsg "connection from $name [",
inet_ntoa($iaddr), "]
at port $port";
spawn sub {
print "Hello there, $name, it's now ", scalar localtime, "\n";
exec '/home/usr/asis/asis/bin/fortune'
or confess "can't exec fortune: $!";
};
}
sub spawn {
my $coderef = shift;
unless (@_ == 0 && $coderef && ref($coderef) eq 'CODE') {
confess "usage: spawn CODEREF";
}
my $pid;
if (!defined($pid = fork)) {
logmsg "cannot fork: $!";
return;
} elsif ($pid) {
logmsg "begat $pid";
return; # I'm the parent
}
# else I'm the child -- go spawn
open(STDIN, "<&Client") || die "can't dup client to stdin";
open(STDOUT, ">&Client") || die "can't dup client to stdout";
## open(STDERR, ">&STDOUT") || die "can't dup stdout to stderr";
exit &$coderef();
}
--
Robert Sturrock _-_|\ E-mail: rns@its.unimelb.edu.au
Information Technology Services / \ Phone: +61 3 9344 7996
The University of Melbourne \_.-.*/ Fax: +61 3 9347 4803
Parkville 3052, AUSTRALIA v
------------------------------
Date: 22 Jul 1997 20:53:07 GMT
From: Scratchie <upsetter@zip1.ziplink.net>
Subject: simple? question
Message-Id: <5r36jj$rtv$1@kayrad.ziplink.net>
Greetings all;
My apologies if this is a FAQ, but I've been wrestling with various perl
documentation for a couple of days now without being able to figure this
out.
My problem is that I'm trying to update my web site so it uses CGI.pm
rather than cgi-lib. I'm trying to add a lot of new functionality and
would rather do it "right" than extend my existing, kludgy scripts (that
were written as I was learning perl 4, for the most part).
Unfortunately, doing so requires learning
* object oriented programming
* the cgi.pm module specifically
* the perl 5 syntax for objects and references
all at the same time.
So my question is:
Why is it that sometimes I can write (for example) "print p;" and
get a "<P>", but sometimes I need to write "print query->p;". OTOH,
sometimes when I write the latter, I get an error message. What does it
mean to write "print query->p" or "print query->h1(This is my heading)"
when neither of these HTML elements seems to have any explicit connection
to the actual data being sent to the cgi script?
Is there some web tutorial somewhere that makes sense of this? The CGI.pm
documentation assumes that you're familiar with using objects and methods,
and sometimes uses "print p" (or whatever) and sometimes "print query->p".
The documentation on objects assumes you're familiar with references, and
vice versa, but I'm really new to all of this (I've been writing perl for
over a year, but mostly sticking to perl 4 features) and I'm just swamped.
There's probably some simple concept that I'm missing here, but I feel
like I'm just chasing my tail, from the CGI.pm documentation, to the Camel
book, to CPAN and back again.
Thanks in advance,
--Art
--------------------------------------------------------------------------
National Ska & Reggae Calendar
http://www.ziplink.net/~upsetter/ska/calendar.html
--------------------------------------------------------------------------
------------------------------
Date: Wed, 23 Jul 1997 18:36:21 +0300
From: nick <nick@alekto.co.il>
Subject: Some problem!
Message-Id: <33D624F5.29EA3D46@alekto.co.il>
Hi!
I've installed PerlIS and Perl 5 on my windows NT 4.0 and tried to run a
very
simple script:
foreach (%ENV){
print "The Env Variable $_ value is \"$ENV($_)\"\n";
}
when I run this script (as a CGI) I get only value for variable
"PERLXS value is PerlIS"
but when I do :
print "REMOTE ADDRESS : \"$ENV(REMOTE_ADDR)\"\n";
foreach (%ENV){
print "The Env Variable $_ value is \"$ENV($_)\"\n";
}
I already get 2 variables in the loop and so on...
What is the problem, why don't I get all the vairables in the first
script?
Nick
------------------------------
Date: Wed, 23 Jul 1997 10:00:54 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: nick <nick@alekto.co.il>
Subject: Re: Some problem!
Message-Id: <Pine.GSO.3.96.970723094930.23677A-100000@kelly.teleport.com>
On Wed, 23 Jul 1997, nick wrote:
> I've installed PerlIS and Perl 5 on my windows NT 4.0 and tried to run a
> very simple script:
>
> foreach (%ENV){
> print "The Env Variable $_ value is \"$ENV($_)\"\n";
> }
You probably want this sort of thing instead.
print map { "$_: $ENV{$_}\n" } sort keys %ENV;
But if you want to see what's going on a little better, you could use this
method, which outputs valid Perl.
for (sort keys %ENV) {
$value = $ENV{$_};
$value =~ s/(["\$\@\\])/\\$1/g; # escape weird chars
print qq{\$ENV{$_} = "$value";\n};
}
> when I run this script (as a CGI) I get only value for variable
> "PERLXS value is PerlIS"
None of these is a CGI script. But you might get what you want if you try
printing the proper headers first. Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 22 Jul 1997 18:39:45 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: tice@hunch.zk3.dec.com (Walter Tice USG)
Subject: Re: Sorting
Message-Id: <8coh7uo8bi.fsf@gadget.cscaper.com>
>>>>> "Walter" == Walter Tice USG <tice@hunch.zk3.dec.com> writes:
Walter> I've been major disapointed w/ the sort in perl until I found this:
Walter> http://www.usenix.org/publications/perl/perl01.html
Walter> HOLA! I've spent a lot of time working ways around what I thought
Walter> was unforgivable oversight, and it was there all along!
Walter> This site also has other fine, real world examples and problem
Walter> solutions, HUZZA Hal Pomeranz !
At about that level of writing, I also have my Unix Review columns
on-line at http://www.stonehenge.com/merlyn/UnixReview/ ... so you
could check that out as well.
I even cover sorting. Fancy that!
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 405 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
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@ora.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: Wed, 23 Jul 1997 13:55:14 -0600
From: jason@cimedia.com (Jason Bodnar)
Subject: Specifying where to look for modules first
Message-Id: <869683151.29502@dejanews.com>
I want to use the newer versions of some modules and my SysAmdin doesn't
want to upgrade yet because it may adversely effect the other users.
So, I created my own perl module directory and installed the modules there
using PREFIX=. I put 'use lib q(/path-to-my-modules/);' at the start of my
programs but it loads the older versions of the modules from the standard
perllib directory. If I print @INC the path to my modules is first. Is
there a way I can specify where to look for modules first?
Jason Bodnar
Internet Programmer
Cox Interactive Media - Austin
jason@cimedia.com
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Thu, 24 Jul 1997 07:43:46 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Re: Sprite Database
Message-Id: <33d700ce.541725@news.wwa.com>
On 24 Jul 1997 06:08:54 GMT, riceexpert@aol.com (RiceExpert) wrote:
>Is anyone here familiar with Sprite.pm?
Yup.
>I've spent so much time trying to get this thing to work, but I haven't been
>able to.
What exactly doesn't work?
>I've copied down examples exactly from the rat book,
To be percise, it is a mouse, a rodent of the family Muridae . It is
not a just some old rat! :-)
>and it still doesn't work.
What exactly doesn't work about it? What error message are you
getting or what do you beleive Sprite.pm should do that it isn't
doing?
>If someone could just give me a simple example of how to add or
>modify an item in a database using Sprite, I would be sooooooo
>grateful.
I was just about to play with it tomorrow, but probably would not be
close to trying to get something to work until next week. I can let
you know my results in a week or so. As for how to add or modify an
item using Sprite.pm, you just use the subset of SQL supported by
Sprite.pm. That much is in the documentation. I'll repeat it for you
here if that helps.
use Sprite;
$rdb = new Sprite ();
$rdb->set_delimiter ("Read", "::");
$rdb->set_delimiter ("Write", "::");
$rdb->set_os ("UNIX");
$rdb->sql (<<Query);
.
.
.
Query
$rdb->close ();
$rdb->close ($database);
_i_n_s_e_r_t - inserts a record into the database:
insert into database
(col1, col2, ... coln)
values
(val1, val2, ... valn)
_E_x_a_m_p_l_e:
insert into my_db
(Player, Years, Points, Championships)
values
('Kareem Abdul-Jabbar', 21, 27, 5)
_N_o_t_e: You do not have to specify all of the fields
in the database! Sprite also does not require you to
specify the fields in the same order as that of the
database.
_u_p_d_a_t_e - updates records that match specified
criteria.
update database set (cond1 OPERATOR value1)[,(cond2
OPERATOR value2)...]
where (cond1 OPERATOR value1)
[and|or cond2 OPERATOR value2 ...]
_E_x_a_m_p_l_e:
update my_db
set Championships = (Championships + 1)
where (Player = 'Larry Joe Bird')
update my_db
set Championships = (Championships + 1),
Years = (12)
where (Player = 'Larry Joe Bird')
>Thank you.
Sure. Anytime.
If you get sick of Sprite.pm and decide you don't really need to use
something like MSQL (http://hughes.com.au/), MySQL
(http://www.tcx.se/), or Postgress95 (http://www.postgresql.org/),
you might try reading Randal Schwartz's September 1995 _Unix Review_
article on tiny text databases at
http://www.stonehenge.com/merlyn/UnixReview/col04.html
Hope this helps. Has anyone else used Sprite.pm to with any success?
Faust Gertz
------------------------------
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 765
*************************************