[21689] in Perl-Users-Digest
Perl-Users Digest, Issue: 3893 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 1 14:05:44 2002
Date: Tue, 1 Oct 2002 11:05:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 1 Oct 2002 Volume: 10 Number: 3893
Today's topics:
Apache::DBI spawns loads of mysqlds <pete@NOSPAMpopcornwebdesign.co.uk>
Re: Apache::DBI spawns loads of mysqlds <richard@zync.co.uk>
Beginning Perl <grahamland@eircom.net>
Re: Beginning Perl <tk@WINDOZEdigiserv.net>
Re: Beginning Perl <Tassilo.Parseval@post.rwth-aachen.de>
Counting Instances of @ in a Scalar (David Garde)
Re: Counting Instances of @ in a Scalar <usenet@tinita.de>
Re: Counting Instances of @ in a Scalar <brittedg@student.gvsu.edu>
Re: Counting Instances of @ in a Scalar <bigj@kamelfreund.de>
Re: Creating and controlling multiple filehandles <goldbb2@earthlink.net>
File Handling Help [\] <notspam@spamfree.dud>
Re: File Handling Help [\] <danb@mail.dnttm.ro>
File::Copy troubleshooting michael.e.grimes@fritolay.com
Floating point question <<A@B>>
Re: Floating point question <wksmith@optonline.net>
Re: Floating point question (Tad McClellan)
Re: Floating point question <<A@B>>
Re: How can I count files in a directory? (Helgi Briem)
Re: How can I count files in a directory? <rubberducky703@hotmail.com>
Re: I need a perl method that works like basedir <jurgenex@hotmail.com>
Message board script with "latest 10 messages" feature? <info@NOSPAMjaridesign.com>
Re: Perl+Cron ... trouble running system() (dale federighi)
Re: Problem with process. <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 1 Oct 2002 17:08:50 +0100
From: "Pete Smith" <pete@NOSPAMpopcornwebdesign.co.uk>
Subject: Apache::DBI spawns loads of mysqlds
Message-Id: <anchal$t4a$1$8300dec7@news.demon.co.uk>
Hi,
I am hosting a site on a Red Hat server running Apache 1.3.23 and mysql
3.23.42.
I am using HTML::Mason, and I have a handler script. I am using Apache::DBI
and assigning it to a global variable in my hadler routine. like so (with
lot of Mason stuff taken out):
package HTML::Mason;
use strict;
{
package HTML::Mason::Commands;
use vars qw($dbh);
use Apache::DBI;
}
sub handler {
my $r = shift;
# Substitute your own configuration for the database
my $dsn = "DBI:mysql:database=***;host=localhost;port=3306";
my $user = '***';
my $passwd = '***';
# get db connection
$HTML::Mason::Commands::dbh = DBI->connect($dsn, $user, $passwd,
{RaiseError => 1, AutoCommit => 1},);
}
1;
the problem is, within hours, if I 'ps -aux | grep mysqld' I see I have
about 70 mysqld processes running. If I leave it carrying on like this, DBI
eventually throws up:
DBI->connect(database=***) failed: Too many connections at SantaUK.pm line
46
in a module (that doesn't use the handler above, but uses DBI) and my
scripts die. Does anyone know what I can do to stop this? I thought
Apache::DBI was supposed to cache connections, but why so many?
Sorry if this is ambiguous or even posted in the wrong group, but I have had
a look around, and I have looked through the perldocs and tutorials/docs at
perl.apache.org.
Any help/explanations would be very much appreciated.
Cheers,
Pete
------------------------------
Date: Tue, 01 Oct 2002 18:07:25 +0100
From: "Richard Gration" <richard@zync.co.uk>
Subject: Re: Apache::DBI spawns loads of mysqlds
Message-Id: <20021001.180725.1597322404.1004@richg.richg.zync>
In article <anchal$t4a$1$8300dec7@news.demon.co.uk>, "Pete Smith"
<pete@nospampopcornwebdesign.co.uk> wrote:
> the problem is, within hours, if I 'ps -aux | grep mysqld' I see I have
> about 70 mysqld processes running. If I leave it carrying on like this,
> DBI eventually throws up:
> DBI->connect(database=***) failed: Too many connections at SantaUK.pm
> line 46
> in a module (that doesn't use the handler above, but uses DBI) and my
> scripts die. Does anyone know what I can do to stop this?
I had the same problem, but with Postgres. My solution was to recompile
Postgres, increasing the number of connections allowed. In fact, I
doubled it. Not a good solution I admit. A friend who also orks as a Perl
prog wrote his own PerlChildInitHandler for apache, which creates and
caches db connections. You could look into that.
Rich
------------------------------
Date: Tue, 1 Oct 2002 17:37:39 +0100
From: "Gyzmo" <grahamland@eircom.net>
Subject: Beginning Perl
Message-Id: <hmkm9.18865$zX3.50537@news.indigo.ie>
Hi,
I'm looking for advice on getting perl installed on my pc running XP &
Debian Linux.I'd like to try and teach myself the language in order to write
programs for the unix,linux and microsoft environments.
Is there a good Development Environment that you can recommend ?
Thank You,
Graham.
------------------------------
Date: Tue, 01 Oct 2002 16:58:31 GMT
From: tk <tk@WINDOZEdigiserv.net>
Subject: Re: Beginning Perl
Message-Id: <h0ljpu8928cg2ajhh17lajn8gg1m85t0rb@4ax.com>
In a fit of excitement on Tue, 1 Oct 2002 17:37:39 +0100, "Gyzmo"
<grahamland@eircom.net> managed to scribble:
| Hi,
|
| I'm looking for advice on getting perl installed on my pc running XP &
| Debian Linux.I'd like to try and teach myself the language in order to write
| programs for the unix,linux and microsoft environments.
|
| Is there a good Development Environment that you can recommend ?
|
| Thank You,
| Graham.
|
Debian should come with Perl by default as part of the OS. As for XP,
http://www.activestate.com/ n download ActivePerl =)
Regards,
tk
--
+--------------------------+
| digiServ Network |
| Web solutions |
| http://www.digiserv.net/ |
+--------------------------+
Remove WINDOZE to reply
------------------------------
Date: 1 Oct 2002 17:03:27 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Beginning Perl
Message-Id: <anckgv$l5r$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Gyzmo:
> I'm looking for advice on getting perl installed on my pc running XP &
> Debian Linux.I'd like to try and teach myself the language in order to write
> programs for the unix,linux and microsoft environments.
So it's about installation? For WinXP you can either get ActivePerl
(http://www.activestate.com) or install cygwin (which is basically a
UNIX-environment for Windows, http://www.cygwin.com). This also has a
Perl-package. The latter is text oriented and will therefore resemble
your Debian's environment.
As for Debian, Perl is certainly already installed. But make sure that
it's at least 5.6.1: 'dpkg -s perl' will tell you.
> Is there a good Development Environment that you can recommend ?
Use what feels more natural for each platform. Under Linux, you are
probably using a good text-editor such as vim or emacs. On a parallel
console you test your programs with
% perl script.pl
or find a way to let your editor do that for you. Both vim and emacs
(and others) can be told to do so.
I don't have much experience with developping Perl applications under
Win. I only use it occasionally. Perhaps 'perldoc -q editor' will help
you:
Found in /usr/share/perl/5.6.1/pod/perlfaq3.pod
Is there an IDE or Windows Perl Editor?
Either way, I would not try to mimic the Debian way on WinXP or vice
versa. They come from too different angles.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: 1 Oct 2002 08:22:50 -0700
From: david_garde@yahoo.com (David Garde)
Subject: Counting Instances of @ in a Scalar
Message-Id: <ca6180e1.0210010722.6ba53b1@posting.google.com>
I am very fresh at writing perl and am trying to get a count on the
number of @ in a scalar variable. The code I wrote is:
$count = 0;
$email = <STDIN>;
while ($email =~ /@/g) {
$count += 1;
print "$count\n";
exit;
}
I want to test for more than 1 instance of an @ mark when someone
inputs their e-mail. However with the above I can't even get a correct
count, it always returns one.
------------------------------
Date: 1 Oct 2002 15:30:40 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: Counting Instances of @ in a Scalar
Message-Id: <ancf30$cn630$1@fu-berlin.de>
David Garde <david_garde@yahoo.com> wrote:
> I am very fresh at writing perl and am trying to get a count on the
> number of @ in a scalar variable.
my $count = $scalar =~ tr/@//;
> The code I wrote is:
> $count = 0;
> $email = <STDIN>;
> while ($email =~ /@/g) {
> $count += 1;
> print "$count\n";
> exit;
you are exiting the program here, already after the
first loop.
hth, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/ \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: Tue, 01 Oct 2002 11:55:40 -0400
From: David Britten <brittedg@student.gvsu.edu>
Subject: Re: Counting Instances of @ in a Scalar
Message-Id: <B9BF3DBC.4BA7%brittedg@student.gvsu.edu>
On 10/1/02 11:22 AM, in article
ca6180e1.0210010722.6ba53b1@posting.google.com, "David Garde"
<david_garde@yahoo.com> wrote:
> I am very fresh at writing perl and am trying to get a count on the
> number of @ in a scalar variable. The code I wrote is:
>
> $count = 0;
> $email = <STDIN>;
> while ($email =~ /@/g) {
> $count += 1;
> print "$count\n";
> exit;
> }
>
> I want to test for more than 1 instance of an @ mark when someone
> inputs their e-mail. However with the above I can't even get a correct
> count, it always returns one.
This is because your while loop will only run once (it contains an exit
statement that terminates the program.)
I'm a bit new at Perl as well, so I'm not positive that /@/g will produce
the behavior you're counting on, although the perlop man page seems to
suggest that it will.
One other (messy) way you could do it would be to use the list return value
of m//g to get all the matches:
@matches = $email =~ /@/g;
Then @matches will contain all of the @ characters, and you could use
@matches in a scalar context to get its size:
$quantity = @matches;
-David Britten
------------------------------
Date: Tue, 01 Oct 2002 17:49:13 +0200
From: Janek Schleicher <bigj@kamelfreund.de>
Subject: Re: Counting Instances of @ in a Scalar
Message-Id: <3d99d180$0$2392$afc38c87@auth.de.news.easynet.net>
David Garde wrote at Tue, 01 Oct 2002 17:22:50 +0200:
> I am very fresh at writing perl and am trying to get a count on the
> number of @ in a scalar variable. The code I wrote is:
>
> $count = 0;
> $email = <STDIN>;
> while ($email =~ /@/g) {
> $count += 1;
> print "$count\n";
> exit;
> }
>
> I want to test for more than 1 instance of an @ mark when someone
> inputs their e-mail. However with the above I can't even get a correct
> count, it always returns one.
Perhaps it's also interesting to read
perldoc -q
"How can I count the number of occurrences of a substring within a string?"
Greetings,
Janek
------------------------------
Date: Tue, 01 Oct 2002 12:22:20 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Creating and controlling multiple filehandles
Message-Id: <3D99CBBC.4D5C30C7@earthlink.net>
Simon Andrews wrote:
[snip]
> I'm still working my way through the code to see what might be the
> problem, but I'd be interested to hear what you found. I'll also look
> into the code Benjamin posted as that looks like a cut down version of
> what Parallel::Jobs was doing behind the scenes which will be useful
> in helping to isolate where things are going wrong.
Actually, mine kinda cheats -- although it starts all N processes in
parallel, it doesn't *quite* let them run in parrallel.
There's a pipe from each process to the main process, and they all run
in parallel *until that pipe is full* ... then they block.
I read from the first one, and doing that unblocks it and allows it to
produce more data, which I read at *whatever rate it produces that
data*, which may be slower than I could do if I were using select() to
choose whichever process has already produced data.
While I'm reading from the first process, the other processes are still
asleep. When I reach EOF on the first process, I go on to the second.
Reading from the second wakes it up if it's gotten blocked due to
filling up it's pipe, and allows it to go and produce more data.
It's only a tiny bit better than running the programs one at a time.
If I were less lazy, I would implement a select loop, which finds which
filehandles have data on them, read the data from *all* those ready
filehandles, and thus allow *all* the processes which blocked due to the
pipes being full to wake up and continue producing data. This would use
more memory, but would take less time to finish running all the
programs.
--
How many Monks would a Chipmonk chip,
if a Chipmonk could chip Monks?
------------------------------
Date: Tue, 01 Oct 2002 17:07:58 GMT
From: Sean O'Dwyer <notspam@spamfree.dud>
Subject: File Handling Help [\]
Message-Id: <notspam-0285C0.13080001102002@typhoon1-0.nyroc.rr.com>
Hi,
I've read most of the applicable entries at <perlfaq5.html> but the
examples and language used there are a little dense for my
non-professional head, so I'm coming here for some help...
My problem is this: I have a script that processes the contents of a
flat database based on inputs from a Web form. A problem arose yesterday
where the person operating the Web form got a bit impatient and trigger
happy while my script was doing its work and hit the form's "SEND"
button a couple of times, sending multiple requests to process the same
data. The result: sixteen duplicate e-mails were sent out for a bunch of
records.
My question is this: is there a way to lock the script while it's busy
so that it doesn't accept further commands until it's finished working.
My other question is this: what happens to those extra commands sent
while the script is locked? Do they queue up, or are they bounced back
with an error?
Kind regards,
Sean
--
Tanta agenda, tantula voluntas.
------------------------------
Date: Tue, 1 Oct 2002 20:51:24 +0200
From: "Dan Borlovan" <danb@mail.dnttm.ro>
Subject: Re: File Handling Help [\]
Message-Id: <ancnat$3lp$1@nebula.dnttm.ro>
> My question is this: is there a way to lock the script while it's busy
> so that it doesn't accept further commands until it's finished working.
- use some locking mechanism of your own in the script (like pid files) - is
there any module that does this?
- use some hidden variable in the form as a "session id" to filter out
duplicates (requires that at least that value is generated in some way, i.e.
using php)
- maybe try FCGI (fastcgi), which does spawn by default only one process and
handles request sequantially
Dan
------------------------------
Date: 1 Oct 2002 17:26:50 GMT
From: michael.e.grimes@fritolay.com
Subject: File::Copy troubleshooting
Message-Id: <anclsq$j03$1@news.netmar.com>
Howdy,
I use the File::Copy module in one of my scripts as follows:
copy("$Full_Origin_Path","$Full_Dot_Share_Path") || &NT_Proc(50, "$Start -
$ENV{COMPUTERNAME} $0 failed on copy", "$Period\_50");
Sometimes, the copy fails and the NT_Proc subroutine executes a page stating
that the copy has failed. I would like to know why the copy is failing. Can
someone suggest a method for capturing the standard error or any other method
for tracking down exactly why the copy is failing?
Any help is appreciated,
Mike
----- Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web -----
http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
NewsOne.Net prohibits users from posting spam. If this or other posts
made through NewsOne.Net violate posting guidelines, email abuse@newsone.net
------------------------------
Date: Tue, 1 Oct 2002 12:03:24 -0500
From: "J" <<A@B>>
Subject: Floating point question
Message-Id: <upjl5lk72q6na8@corp.supernews.com>
Hopefully someone out there can help me with this.
I have this script that parses the date month and year
out of a scalar of the format yyyymmdd. The problem
is when input the value 20021001 the day returns 00
instead of one. I printed out some of the steps to see what
was happening, and you can see by my comment what
the output was. Im am using version 5.6.1. What do you think
is happening here?
$Date = $ARGV[0];
$yr = int($Date/10000);
$mo = int((($Date/10000) - int($Date/10000)) * 100);
$dy = int((($Date/100) - int($Date/100)) * 100);
print int($Date/100)."\n";
print (($Date/100) - int($Date/100))."\n";# output 0.0099999999999999999997
print "Date entered $Date\n";
print "Day = $dy Month = $mo Year = $yr\n";
------------------------------
Date: Tue, 1 Oct 2002 13:26:08 -0400
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Floating point question
Message-Id: <vVkm9.43599$9d3.1882974@news4.srv.hcvlny.cv.net>
"J >" <<A@B> wrote in message news:upjl5lk72q6na8@corp.supernews.com...
> Hopefully someone out there can help me with this.
> I have this script that parses the date month and year
> out of a scalar of the format yyyymmdd. The problem
> is when input the value 20021001 the day returns 00
> instead of one. I printed out some of the steps to see what
> was happening, and you can see by my comment what
> the output was. Im am using version 5.6.1. What do you think
> is happening here?
>
> $Date = $ARGV[0];
> $yr = int($Date/10000);
> $mo = int((($Date/10000) - int($Date/10000)) * 100);
> $dy = int((($Date/100) - int($Date/100)) * 100);
>
> print int($Date/100)."\n";
> print (($Date/100) - int($Date/100))."\n";# output
0.0099999999999999999997
> print "Date entered $Date\n";
> print "Day = $dy Month = $mo Year = $yr\n";
>
>
"perldoc -f int" explains the problem.
Much better to treat your data as text.
use strict;
use warnings;
my $Date = '20021001';
my ($yr,$mo,$dy) = $Date =~m/(\d\d\d\d)(\d\d)(\d\d)/;
print int($Date/100)."\n";
print "Date entered $Date\n";
print "Day = $dy Month = $mo Year = $yr\n";
Bill
------------------------------
Date: Tue, 01 Oct 2002 17:30:35 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Floating point question
Message-Id: <slrnapjmn1.1nd.tadmc@magna.augustmail.com>
J <<A@B> wrote:
> Subject: Floating point question
Why are you treating the date as a number in the first place?
> Hopefully someone out there can help me with this.
> I have this script that parses the date month and year
> out of a scalar of the format yyyymmdd.
Treat it like a string, and it gets a lot easier:
my($year, $month, $day) = $Date =~ /^(\d{4})(\d\d)(\d\d)$/;
> What do you think
> is happening here?
Perhaps your Question is Asked Frequently.
> print (($Date/100) - int($Date/100))."\n";# output 0.0099999999999999999997
perldoc -q 9999
"Why am I getting long decimals (eg, 19.9499999999999)
instead of the numbers I should be getting (eg, 19.95)?"
Yep.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 1 Oct 2002 13:04:39 -0500
From: "J" <<A@B>>
Subject: Re: Floating point question
Message-Id: <upjooeq5n8egf0@corp.supernews.com>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnapjmn1.1nd.tadmc@magna.augustmail.com...
> J <<A@B> wrote:
>
> > Subject: Floating point question
>
>
> Why are you treating the date as a number in the first place?
I like to use perl to test functions that I am going to write in
another langauge where integers and string are different data types.
------------------------------
Date: Tue, 01 Oct 2002 15:57:49 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: How can I count files in a directory?
Message-Id: <3d99c314.1927204813@news.cis.dfn.de>
On Tue, 1 Oct 2002 10:40:08 -0400, "Ilya Sterin"
<isterin@nospam.com> wrote:
Don't top-post. It annoys the regular and
severely reduces your chances of people
taking you seriously.
>"Rubber Duck" <rubberducky703@hotmail.com> wrote in message
>news:anblvf$cktur$1@ID-116287.news.dfncis.de...
>> How can I count files in a directory?
>>
>> Is their a module or a method in a perl module which will scan a top level
>> directory and count the number of files in each of the folders/directories
>> below it?
>>
>> I also need to check for the file index.html in each folder, any
>> package/method which allows this would be ideal.
>>
>> Essentially, all I need is just a list of directory names and a number
>> indicating the number of files in that specific folder.
>>
>> Any ideas? Where should i be looking?
>my $dir = opendir("path/to/dir");
This will not work as you have not supplied enough
arguments for opendir.
It should be:
opendir, DIR, $dir
or die "Cannot opendir $dir:$!\n";
>my $count;
>
>$count++ while (readdir($dir));
This will count . and .. and should be fed a dirhandle,
DIR, not the directory path, $dir.
Here is way that actually works:
#!perl
use warnings;
use strict;
use File::Find;
my $dir = 'C:/tmp';
find \&countfiles_per_dir,$dir;
sub countfiles_per_dir
{
if (-d $File::Find::name)
{
opendir DIR, $File::Find::name
or warn "Cannot opendir $File::Find::name:$!\n";
my @files = grep !/^\.{1,2}$/, readdir DIR;
closedir DIR;
my $count = @files;
print "$File::Find::name contains $count files\n";
}
}
__END__
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Tue, 1 Oct 2002 17:24:25 +0100
From: "Rubber Duck" <rubberducky703@hotmail.com>
Subject: Re: How can I count files in a directory?
Message-Id: <anci6k$cq98q$1@ID-116287.news.dfncis.de>
Top Post????
"Helgi Briem" <helgi@decode.is> wrote in message
news:3d99c314.1927204813@news.cis.dfn.de...
> On Tue, 1 Oct 2002 10:40:08 -0400, "Ilya Sterin"
> <isterin@nospam.com> wrote:
>
> Don't top-post. It annoys the regular and
> severely reduces your chances of people
> taking you seriously.
>
> >"Rubber Duck" <rubberducky703@hotmail.com> wrote in message
> >news:anblvf$cktur$1@ID-116287.news.dfncis.de...
> >> How can I count files in a directory?
> >>
> >> Is their a module or a method in a perl module which will scan a top
level
> >> directory and count the number of files in each of the
folders/directories
> >> below it?
> >>
> >> I also need to check for the file index.html in each folder, any
> >> package/method which allows this would be ideal.
> >>
> >> Essentially, all I need is just a list of directory names and a number
> >> indicating the number of files in that specific folder.
> >>
> >> Any ideas? Where should i be looking?
>
> >my $dir = opendir("path/to/dir");
>
> This will not work as you have not supplied enough
> arguments for opendir.
>
> It should be:
> opendir, DIR, $dir
> or die "Cannot opendir $dir:$!\n";
>
> >my $count;
> >
> >$count++ while (readdir($dir));
>
> This will count . and .. and should be fed a dirhandle,
> DIR, not the directory path, $dir.
>
> Here is way that actually works:
>
> #!perl
> use warnings;
> use strict;
> use File::Find;
> my $dir = 'C:/tmp';
>
> find \&countfiles_per_dir,$dir;
>
> sub countfiles_per_dir
> {
> if (-d $File::Find::name)
> {
> opendir DIR, $File::Find::name
> or warn "Cannot opendir $File::Find::name:$!\n";
> my @files = grep !/^\.{1,2}$/, readdir DIR;
> closedir DIR;
> my $count = @files;
> print "$File::Find::name contains $count files\n";
> }
> }
> __END__
> --
> Regards, Helgi Briem
> helgi AT decode DOT is
>
> A: Top posting
> Q: What is the most irritating thing on Usenet?
> - "Gordon" on apihna
------------------------------
Date: Tue, 1 Oct 2002 10:11:54 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: I need a perl method that works like basedir
Message-Id: <3d99d754$1@news.microsoft.com>
Roland Reichenberg wrote:
> does anybody know if there is a function like "basedir" in perl?
No, but there is a module File::Basename
jue
------------------------------
Date: Tue, 01 Oct 2002 13:30:44 -0400
From: Jari Hakkarainen <info@NOSPAMjaridesign.com>
Subject: Message board script with "latest 10 messages" feature?
Message-Id: <r1mjpuc7fp5gh05pjs06bdhp8g0nfj1h9f@4ax.com>
Is there a message board script that allows me to show the latest 5-10
messages posted in different board categories via an external page,
using SSI?
I am looking for a message board script that functions in Perl and
that has fairly advanced features, as on Ikonboard, UBB and phpBB.
Though, perhaps most importantly, I want to be able to show the titles
of the latest messages on a page outside the message board. I have
searched the Internet without a success.
I would appreciate if anyone could help me to find one.
Please reply in e-mail to: jarre@NOSPAMsci.fi (remove "NOSPAM" before
sending a message), or directly to this thread.
------------------------------
Date: 1 Oct 2002 09:25:31 -0700
From: dfederighi@yahoo.com (dale federighi)
Subject: Re: Perl+Cron ... trouble running system()
Message-Id: <1018a300.0210010825.7d0f493c@posting.google.com>
Martien Verbruggen <mgjv@tradingpost.com.au> wrote in message news:<slrnapignm.t64.mgjv@verbruggen.comdyn.com.au>...
> On Tue, 01 Oct 2002 03:20:42 GMT,
> Tad McClellan <tadmc@augustmail.com> wrote:
> > dale federighi <dfederighi@yahoo.com> wrote:
> >
> >> I am running a perl script that checks to see if the Tomcat server is
> >> down, and if it is, does a simple restart (through system() and calls)
>
> [snip]
>
> >> foreach my $line(@LOG_LINES)
> >> {
> >> if( $line =~ /Starting/ )
> >> {
> >> $tomcat_started = 1;
> >> }
> >> else
> >> {
> >> $tomcat_started = 0;
> >> }
> >> }
> >
> >
> > You could replace that entire foreach with:
> >
> > my $tomcat_started = grep /Starting/, @LOG_LINES;
> >
> > or do away with the @LOG_LINES temporary variable as well:
> >
> > my $tomcat_started = grep /Starting/, <FILE>;
>
> But that is not equivalent (even though it may very well be closer to
> what is actually intended).
>
> I am not sure what the OP is trying to ascertain with that code, or
> what the log file looks like, but the end result could very well be
> different.
>
> A log file like:
>
> Starting Whatever
> More lines without that string in them
>
> would result in $tomcat_started being 0 with the OP's code, and 1 with
> your code.
>
> The OP is checking whether the last line in the log file contains
> "Starting" (and could do that much more efficiently), while you count
> the number of lines that contain that string.
>
> Without knowing what can appear in that log file, I won't pretend to
> know what is correct and what isn't.
>
> Example 1:
>
> Starting Tomcat
> Fatal error: Exiting Tomcat
>
> (OP's code right, yours wrong)
>
> Example 2:
>
> Starting Tomcat
> Tomcat still happily running, just being chatty
>
> (OP's code wrong, yours right)
>
> Unless Tomcat is very, very quiet, I doubt that either of the two
> tests is all there is to it.
>
> Martien
> Guys, I appreciate the critique on the logic, but the main problem is this ... I am running the script as root, either on the command-line or in CRON. The script itself works ... and has been tested countless times ... the logic my need to be reworked, and that is fine, but the problem is that it WILL run from the command line with the desired effect, but will NOT run from a CRONTAB entry ????
This is the issue.
daleF
------------------------------
Date: Tue, 01 Oct 2002 13:21:40 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Problem with process.
Message-Id: <3D99D9A4.250D371E@earthlink.net>
Franklin Lee wrote:
>
> Hello, folks. I'm confused with process invoke.
> We know that we can invoke one Unix command in
> two way.
More than that:
system, exec, ``, qx, readpipe, open.
(Of course, ``, qx, and readpipe are all approximately the same; the
main difference being that `` and qx are quoting operators, and readpipe
is a function).
There's also the modules IPC::Open2 and IPC::Open3, which provide
functions open2() and open3(), respectively.
> One: use system.
> my $prtvtoc="/usr/sbin/prtvtoc";
> system($prtvtoc c0t0d0s7);
I think you mean:
system( $prtvtoc, "c0t0d0s7" );
Or:
system( "$prtvtoc c0t0d0s7" );
The one which passes a list instead of a string is generally considered
better (safer, and maybe faster too), since there's no chance of the
unix shell being invoked to seperate the arguments.
> Other: usr ``
> `/usr/sbin/prtvtoc c0t0d0s7`;
>
> What's difference?
When you use system(), it simply runs the program; if the program reads
data from stdin, it gets it from *your* stdin; if the program sends to
stdout, it sends to *your* stdout.
When you use ``, qx, or readpipe(), it captures the stdout of the
program, instead of sending it's stdout to your own stdout. The return
value is either a string or a list containing that captured data.
When you use exec, it doesn't start a new process, but rather replaces
your current process with the specified one.
If you use open to start a program (eg:
my $process_id = open(FH, "-|", "$prtvtoc c0t0d0s7");
), it starts the program as a seperate process (just like system and qx
do), but doesn't wait for it to finish. You are expected to read data
from FH (or write to it, if you used "|-" instead of "-|"), and close
the handle when you're done and want to wait for the program to finish.
The questions to ask are to decide which to use are:
1) Does it read input?
If so, should it read from your stdin?
2) Does it produce output?
If so:
Do you want it to send it to your stdout?
Do you want to capture that output?
3) Do you want to wait for the process to finish, or do you want the
other program and your own program to run in parallel?
4) Do you plan on doing anything else in the current process after
that program is run? (If no, then exec() might be the right choice).
Without answers, we can't really advise you as to which you want.
--
How many Monks would a Chipmonk chip,
if a Chipmonk could chip Monks?
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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.
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 V10 Issue 3893
***************************************