[6509] in Perl-Users-Digest
Perl-Users Digest, Issue: 134 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 17 19:07:55 1997
Date: Mon, 17 Mar 97 16:00:19 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 17 Mar 1997 Volume: 8 Number: 134
Today's topics:
array of filehandles ...how to? <rjm@theory.chem.ubc.ca>
inheritance with hash variables (Eric Marc Mcmillan)
Interpolating variable hash keys <chris@ixlabs.com>
Re: learning perl <tchrist@mox.perl.com>
Re: Multiple substitutions (Eric Bohlman)
Non-Perl Process Controller Module ? <dorman@lee.s3i.com.anti-spam>
Re: perl -w <tchrist@mox.perl.com>
Re: perl and cgi <tchrist@mox.perl.com>
Re: Perl Compiler <tchrist@mox.perl.com>
Perl DB? <jday@msmailgw.sdsmt.edu>
Re: Perl for NT ***Help**** (Reinoud van Leeuwen)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 17 Mar 1997 15:49:08 -0800
From: Richard Moss <rjm@theory.chem.ubc.ca>
Subject: array of filehandles ...how to?
Message-Id: <332DD874.41C6@theory.chem.ubc.ca>
Hi ya,
I'd like to open and use and array of filehandles, but can't figure out
how to (ahh - I havent' used references much before ;-)
At the moment I'm trying:
for (for ($i=0;$i<=5;$i++) {
open( XXX,">$i");
$fh[$i] = \*XXX;
}
...I can't do a: open( $fh[$i], ">$i") cause that won't compile.
But when I do the above, all the references in the fh array end up
pointing to the same filehandle, the last one opened. So I was
wondering whether someone can tell me how you make an array of
filehandles, like above, and then feed them into OPEN.
Also, with the above, I write to them with something like:
printf( {$fh[$i]} "blah blah blah\n" );
....is this the "right" way to do that?
thanks for any help/info,
Richard
------------------------------
Date: 17 Mar 1997 23:09:27 GMT
From: emcmilla@cps.msu.edu (Eric Marc Mcmillan)
Subject: inheritance with hash variables
Message-Id: <5gkiv7$8vf$1@msunews.cl.msu.edu>
I am trying to do inheritance using anonymous hash to hold
instance variables. Inheritance doesn't seem to be working
the way I implement it. If I don't use anonymous hash to hold
the instance variables it works fine. I have a small snippit
of code that I thought should work. The code is in three separate
files:
package main;
require derived;
$a = Derived->new(pid => 999);
print "pid = ", $a->{pid}, "\n";
============================================
package Base;
sub new {
my $type = shift;
my %param = @_;
my $self = {};
$self->{pid} = $param{pid};
return bless $self, $type;
}
1;
==============================================
package Derived;
use Base;
@ISA = qw( Base );
sub new {
my $type = shift;
my $self = Base->new;
return bless $self, $type;
}
1;
=============================================
Is there something I'm not implementing correctly?
------------------------------
Date: Mon, 17 Mar 1997 13:22:02 -0800
From: Chris Schoenfeld <chris@ixlabs.com>
Subject: Interpolating variable hash keys
Message-Id: <332DB5FA.50DA@ixlabs.com>
Ran in to this quirk a long time ago, but haven't seen it since I moved
to Perl 5.003.
The quirk is that Perl sometimes requires the hash keys (i.e.
$hashref->{$key} to be put in double-quotes:
$hashref->{"$key"} in order to be correctly interpolated.
I have the following two sequential lines in some code:
print $newref->{$keys}; # Requires no "'s
if($newref->{$keys}=~/\~\$arg/){ # Uninitialized value!
As soon as I put the double quotes around $keys in the second line, the
program ran fine.
The problem is clearly dependant on the context of it's usage.
--
Chris Schoenfeld
IX Development Laboratories
Santa Rosa, California
(707)-543-8030 Ext. 12
------------------------------
Date: 17 Mar 1997 23:49:27 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: learning perl
Message-Id: <5gkla7$fpo$6@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, bd@internet-etc.com writes:
:The best starting point is http://www.cis.ufl.edu/perl/ - the University
:of Florida Perl Archive. There is no substitute....
This seems somewhat ingenuous.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
With a PC, I always felt limited by the software available. On Unix, I am
limited by my knowledge. --Peter J. Schoenster <pschon@baste.magibox.net>
------------------------------
Date: Mon, 17 Mar 1997 23:29:11 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Multiple substitutions
Message-Id: <ebohlmanE77nwo.BHD@netcom.com>
Michael Schuerig (uzs90z@uni-bonn.de) wrote:
: I'm trying to do multiple substitutions in a file without iterating over
: an array of old-new pairs. I had a look at the FAQ and read the thread
: in this group about matching multiple patterns, but it wasn't of much
: help to me. Apparently the problem is in the eval below. Can anyone give
: me an idea of what I'm doing wrong?
[snip]
: $replacements .= "\$ln=s/$key/$value/go;";
You want "...ln=~s...
Remember that $scalar=s/old/new/ performs substitution on $_ and sets
$scalar to the number of times the substitution took place (which will be
0 or 1 unless there's a g modifier on the s), whereas $scalar=~s/old/new/
performs substitution on $scalar.
'tis a good idea to get ahold of the Camel book and read the section on
regular expressions and matching several times (do something else in
between the readings; otherwise your brain won't absorb everything).
------------------------------
Date: 17 Mar 1997 15:44:46 -0500
From: Clark Dorman <dorman@lee.s3i.com.anti-spam>
Subject: Non-Perl Process Controller Module ?
Message-Id: <dafo22qpt.fsf@s3i.com>
Greetings,
I have a rather large computer model (written in simscript)
that takes a long time to run, but for statistical reasons has to have
a number of iterations. What I would like to do is create a perl
control program that will spawn off runs on my system (UNIX, Sun
Sparcs, Solaris). Here's what I want:
What I tell the program:
Number of Runs to do
Names of Machines to run on
Limits on CPU load (per machine)
What the program does:
Figures out what machines are up
Spawns runs on machines with load < load_limit
cleans up runs that crash
kills runs that are runaways
brings output of successful runs to appropriate dir
I've written some perl code that is rather fragile and ugly.
It uses rup to see how the machines are doing, makes system calls to
rsh to start copies of itself on the machines with low limits, keeps a
database of what runs complete, and uses "at" to restart itself later
on. It looks like this:
check for command line options (-e is a run, -m is a monitor job)
if not a run or monitor, must be initial run
make sure things are ok with input data files
schedule a monitor job: system "echo $0 -m | at now + 1 minute"
if a monitor job
clean up old runs
check for completed runs in the database
kills runs in database that exceed max runtime
rup machines to figure out what can be used
foreach good machine
system "rsh machine $0 -e run_number"
add run to database
schedule a monitor job for now + 10 minutes
if a run
make a new directory
chdir to new directory
system "big_model"
if it finishes, create a file giving information
if it dies for some reason, create a file with that info
As I said, it's ugly. Maybe I should have it with a loop and sleeps
for a while, rather than schedule a new run of itself. Also, passing
information back from a run as to how it turned out is through these
files, which is a bother. I don't want to deal directly with the
database in the runs since it may be opened by a monitor job (or
another run) at the same time. The database itself is ugly since I'm
kind of constrained by the single associative array data structure.
Right now, I'm using the default database, a la the llama book.
Is there a module that can handle these sorts of problems? I've
looked in CPAN and the process servers are the closest thing, but they
don't seem to really do it. The closest is Proc::Simple, but it's not
clear how to deal with processes over a network. What I really what
in a general system process server, but I can't find one. Has someone
written one? Should I be using fork instead, which is being used by
Proc::Simple? Should I make multiple perl programs rather than one
big one?
--
Clark Dorman
dorman@s3i.com (anti-spam added to from: address above, sorry)
------------------------------
Date: 17 Mar 1997 21:44:55 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: perl -w
Message-Id: <5gke0n$a29$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Rick Tan <rick.tan@Eng.Sun.COM> writes:
:Hi,
:
:What does the following message telling me?
:
: Use of uninitialized value at ./craid.GOOD line 432, <INPUT> chunk 1.
:
:In my Perl script, I have the following:
:
: open (INPUT, "somefile");
: .
: .
: .
: while (chop($line=<INPUT>) { ===> line 432
It's telling you that testing to see whether the last character
in a line is not a null byte is a various dodgy thing. chop()
returns the byte. But it's all false at the end, so chop chops
nothing and returns nothing. But it's the undef kind of nothing.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
It is Unix. It is possible to overcome any number of these bogus features. --pjw
------------------------------
Date: 17 Mar 1997 21:42:04 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: perl and cgi
Message-Id: <5gkdrc$a29$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Bob_Franklin@illinova.com writes:
:Is there a Perl plug-in or is there a way to preload Perl
:for the Netscape and Oracle Web Servers (Unix/NT)?
:
:I want to avoid the overhead of loading the Perl executable
:each time a Perl CGI script is invoked.
:
:(I know MS IIS has perliis.dll.)
>From part 3 of the FAQ:
=head2 How can I make my CGI script more efficient?
Beyond the normal measures described to make general Perl programs
faster or smaller, a CGI program has additional issues. It may be run
several times per second. Given that each time it runs it will need
to be re-compiled and will often allocate a megabyte or more of system
memory, this can be a killer. Compiling into C B<isn't going to help
you> because the process start-up overhead is where the bottleneck is.
There are at least two popular ways to avoid this overhead. One
solution involves running the Apache HTTP server (available from
http://www.apache.org/) with either of the mod_perl or mod_fastcgi
plugin modules. With mod_perl and the Apache::* modules (from CPAN),
httpd will run with an embedded Perl interpreter which pre-compiles
your script and then executes it within the same address space without
forking. The Apache extension also gives Perl access to the internal
server API, so modules written in Perl can do just about anything a
module written in C can. With the FCGI module (from CPAN), a Perl
executable compiled with sfio (see the F<INSTALL> file in the
distribution) and the mod_fastcgi module (available from
http://www.fastcgi.com/) each of your perl scripts becomes a permanent
CGI daemon processes.
Both of these solutions can have far-reaching effects on your system
and on the way you write your CGI scripts, so investigate them with
care.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
I have made this letter longer than usual because I lack the time to
make it shorter.
--Blaise Pascal
------------------------------
Date: 17 Mar 1997 22:27:56 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Perl Compiler
Message-Id: <5gkghc$bfq$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
steve@golf.com (Steven Sajous) writes:
:Does anyone know where I can find a Perl compiler, and have any
:instr5uctions on how to use one?
I suspect that you really mean "where can you get Perl". See the FAQ.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
Finally, which rhymes with enough --
Though, through, plough, or dough, or cough?
------------------------------
Date: Mon, 17 Mar 1997 15:51:25 -0700
From: "Jon T. Day" <jday@msmailgw.sdsmt.edu>
Subject: Perl DB?
Message-Id: <332DCAEC.2ED5@msmailgw.sdsmt.edu>
Is there a perl database newsgroup?
If anybody knows what the name of it is, I would appreciate
it!
Jon
------------------------------
Date: Mon, 17 Mar 1997 23:04:28 GMT
From: reinoud@xs4all.nl (Reinoud van Leeuwen)
Subject: Re: Perl for NT ***Help****
Message-Id: <332dcd38.19842762@news.xs4all.nl>
On 17 Mar 1997 16:27:36 GMT, "Jonathan Tracey" <jont@uunet.pipex.com>
wrote:
>Please help me before I go insane!
>
>How can I stop the Perl window closing as soon as it encounters an error. I
>cannot read the error messages as the windows closes like lightning.
>
(I have not tried this myself)
(assuming that Perl sets an errorlevel..., I'm not sure about this)
change the association of the .perl files to
\path\perl.exe -w %1 %2 %3 %4 %5 %6 || pause
the "||" is a NT command extension over dos and only executes the
second command when the first sets an errorlevel (just the way the
Perl construction "open file OR die")
__________________________________________________
Reinoud van Leeuwen reinoud@xs4all.nl
http://www.xs4all.nl/~reinoud
I specifically DO NOT give anyone permission to use my email adress
for any commercial or non commercial mailings. I will bill everyone
who sends me this kind of mail for wasting my time. Under Dutch law,
people who don't let me know they disagree with such a bill are obliged
to pay it.
------------------------------
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 134
*************************************