[22460] in Perl-Users-Digest
Perl-Users Digest, Issue: 4681 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 7 18:07:05 2003
Date: Fri, 7 Mar 2003 15:05:11 -0800 (PST)
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, 7 Mar 2003 Volume: 10 Number: 4681
Today's topics:
A quick Socket Question <extendedpartition@nospam.yahoo.com>
Re: A quick Socket Question <abigail@abigail.nl>
Re: A quick Socket Question <extendedpartition@nospam.yahoo.com>
Almost match? (Michael Robbins)
Re: Almost match? <s_grazzini@hotmail.com>
Re: Almost match? <tore@aursand.no>
any simple way to detect the real end of a command in a (mkkwong)
Re: any simple way to detect the real end of a command <abigail@abigail.nl>
Re: any simple way to detect the real end of a command (Malcolm Dew-Jones)
Re: Can I Get Neater Hyperlinks in Emails <mbudash@sonic.net>
Catching errors using DBI <geoff.news7@alphaworks.co.uk>
Re: Catching errors using DBI <mbudash@sonic.net>
Re: Catching errors using DBI <nobull@mail.com>
Re: Catching errors using DBI <geoff.news7@alphaworks.co.uk>
Re: CGI query string help <wsegrave@mindspring.com>
event notification Perl - Windows (martin)
Re: Floyd-Warshall on undirected graph? <abigail@abigail.nl>
Re: Floyd-Warshall on undirected graph? <abigail@abigail.nl>
foreach in while-block cancels while (mbuechner)
Re: foreach in while-block cancels while <tore@aursand.no>
Re: foreach in while-block cancels while <wcitoan@NOSPAM-yahoo.com>
Re: I want to know the line n umber of the error ! <tore@aursand.no>
Re: I want to know the line n umber of the error ! <tore@aursand.no>
Re: I want to know the line n umber of the error ! <noreply@gunnar.cc>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 7 Mar 2003 15:51:13 -0600
From: "Extended Partition" <extendedpartition@nospam.yahoo.com>
Subject: A quick Socket Question
Message-Id: <3e69149c_2@nntp2.nac.net>
Hello Everyone,
For my own edification, I'm building a small chat server similar to
geektalkd in Perl. Since I'm fairly new to socket programming in Perl I have
the following question:
1. Let's say I have 20 client connections to the server. Would this code
work if I wanted to send data to every connected client (assuming that the
socket connection is called $mySocket):
for each $sock (@mySocket){
print $sock $message;
}
Here is my reasoning on why this should work: I am assuming that multiple
socket connections are stored in an array. This array (called $mySocket) is
able to be cycled through. Am I correct? If not, how would I accomplish this
task?
Thanks!
Anthony
--
---
Sick of Spam?
Stop it NOW!!
http://www.safferconsulting.com/spamviper
------------------------------
Date: 07 Mar 2003 22:01:19 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: A quick Socket Question
Message-Id: <slrnb6i5lf.r9j.abigail@alexandra.abigail.nl>
Extended Partition (extendedpartition@nospam.yahoo.com) wrote on
MMMCDLXXV September MCMXCIII in <URL:news:3e69149c_2@nntp2.nac.net>:
:: Hello Everyone,
::
:: For my own edification, I'm building a small chat server similar to
:: geektalkd in Perl. Since I'm fairly new to socket programming in Perl I have
:: the following question:
::
:: 1. Let's say I have 20 client connections to the server. Would this code
:: work if I wanted to send data to every connected client (assuming that the
:: socket connection is called $mySocket):
::
:: for each $sock (@mySocket){
:: print $sock $message;
:: }
Eh, no. @mySocket and $mySocket don't have much of a relationship.
:: Here is my reasoning on why this should work: I am assuming that multiple
:: socket connections are stored in an array. This array (called $mySocket) is
:: able to be cycled through. Am I correct? If not, how would I accomplish this
:: task?
Well, it's fine to assume multiple connections are stored in an array,
but that doesn't make it so. It's not impossible though, and not hard
to do, but you have to do it. It won't happen by assuming.
Furthermore, $mySocket is a scalar, holding a single value. It's not
an array. $mySocket could be a reference to an array, or you could
mean @mySocket, which is an array.
You might want to check out the POE module. It has a lot of functionality
you could use.
Abigail
--
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$==-2449231+gm_julian_day+time);do{until($=<$#r){$_.=$r[$#r];$=-=$#r}for(;
!$r[--$#r];){}}while$=;$,="\x20";print+$_=>September=>MCMXCIII=>=>=>=>=>=>=>=>'
------------------------------
Date: Fri, 7 Mar 2003 16:14:07 -0600
From: "Extended Partition" <extendedpartition@nospam.yahoo.com>
Subject: Re: A quick Socket Question
Message-Id: <3e6919ed_1@nntp2.nac.net>
> You might want to check out the POE module. It has a lot of functionality
> you could use.
Much thanks!
Anthony
------------------------------
Date: 7 Mar 2003 08:38:01 -0800
From: michael.robbins@us.cibc.com (Michael Robbins)
Subject: Almost match?
Message-Id: <c6c65b14.0303070508.2e255419@posting.google.com>
I'm trying to get a percent match value like this:
`Bloomberg' vs. `Bl0omberg' returns 89% because all letters match but
1
`Bloomberg' vs. `Bromide' returns 11% because only one of the letters
match
The reason is that I am getting text data that is poorly typed and I
must be able to tell that when someone typed `Bl0omberg' they probably
meant `Bloomberg' but when they typed `Bromide' they probably didn't.
If I could do it as a one-liner, all the better.
Any ideas?
As always, TIA
------------------------------
Date: Fri, 07 Mar 2003 17:15:48 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: Almost match?
Message-Id: <8t4aa.55316$Mh3.21301220@twister.nyc.rr.com>
Michael Robbins <michael.robbins@us.cibc.com> writes:
> I'm trying to get a percent match value like this:
>
> `Bloomberg' vs. `Bl0omberg' returns 89% because all letters
> match but `Bloomberg' vs. `Bromide' returns 11% because only
> one of the letters match
>
Try String::Approx
$ google perl "fuzzy matching"
--
Steve
------------------------------
Date: Fri, 07 Mar 2003 18:54:18 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Almost match?
Message-Id: <pan.2003.03.07.16.51.11.813780@aursand.no>
On Fri, 07 Mar 2003 08:38:01 -0800, Michael Robbins wrote:
> The reason is that I am getting text data that is poorly typed and I
> must be able to tell that when someone typed `Bl0omberg' they probably
> meant `Bloomberg' but when they typed `Bromide' they probably didn't.
Definitely not a one-liner, but it gives you so much more:
String::Approx
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: 7 Mar 2003 11:50:27 -0800
From: mkwong@wideopenwest.com (mkkwong)
Subject: any simple way to detect the real end of a command in a perl script?
Message-Id: <4977b250.0303071150.3bde08f6@posting.google.com>
I intend to write some simple tools to help myself in writing perl
programs. The tool will read a perl script and analyze the content and
perhaps generate some useful information.
One of the first problems I encounter is to figure out whether a ;
found in a line in the script is really the end of a command. A
similar problem is how can we tell the end of those commands that may
not end in a ; (like the last statement in a block).
Obviously the perl debugger or the useful perltidy() utility has this
capabilty. I am way too lazy (aka don't know enough) to try to dig
into those to find out how they do it. I don't really need the full
power like those tools to parse the complete perl syntax - it is
enough if I can simply determine that the ; I see is not part of a
string value, or part of a here doc, or a regex, or a comment etc.
Similarly, if I see an enclosing }, how do I know whether that is the
end of a code block and not part of a hash notation, or part of a
string value, or a here doc or a regex, etc.
A related problem is: If I see a #, how can I write my tool to
distinguish whether it begins a comment, or not (again it can be part
of a string value, here doc, etc.).
Does any one know if there is an easy way or if some modules are
available (without me having to chase through the entire set of perl
syntax rules) to do those or am I wishing too much?
Thanks for any help.
------------------------------
Date: 07 Mar 2003 21:47:28 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: any simple way to detect the real end of a command in a perl script?
Message-Id: <slrnb6i4rg.r9j.abigail@alexandra.abigail.nl>
mkkwong (mkwong@wideopenwest.com) wrote on MMMCDLXXV September MCMXCIII
in <URL:news:4977b250.0303071150.3bde08f6@posting.google.com>:
{} I intend to write some simple tools to help myself in writing perl
{} programs. The tool will read a perl script and analyze the content and
{} perhaps generate some useful information.
This is a very hard problem. There are some modules in the B::
namespace that do stuff like that, but they were written by some
very clever minds, with lots and lots of deep knowledge of the
Perl internals.
{} One of the first problems I encounter is to figure out whether a ;
{} found in a line in the script is really the end of a command. A
{} similar problem is how can we tell the end of those commands that may
{} not end in a ; (like the last statement in a block).
{}
{} Obviously the perl debugger or the useful perltidy() utility has this
{} capabilty. I am way too lazy (aka don't know enough) to try to dig
{} into those to find out how they do it. I don't really need the full
{} power like those tools to parse the complete perl syntax - it is
{} enough if I can simply determine that the ; I see is not part of a
{} string value, or part of a here doc, or a regex, or a comment etc.
The only way to do that is by parsing Perl. Any heuristic you can come
up with that doesn't involve parsing Perl, I can find an example that
fails.
{} Similarly, if I see an enclosing }, how do I know whether that is the
{} end of a code block and not part of a hash notation, or part of a
{} string value, or a here doc or a regex, etc.
You will have to parse Perl. Note that even perl itself doesn't always
guess right whether a '{' starts a code block, or a hash reference.
{} A related problem is: If I see a #, how can I write my tool to
{} distinguish whether it begins a comment, or not (again it can be part
{} of a string value, here doc, etc.).
Guess what? You'd need to parse Perl.
{} Does any one know if there is an easy way or if some modules are
{} available (without me having to chase through the entire set of perl
{} syntax rules) to do those or am I wishing too much?
Lookat the backend modules in the B:: namespace.
Abigail
--
perl -wle'print"Êõóô áîïôèåò Ðåòì Èáãëåò"^"\x80"x24'
------------------------------
Date: 7 Mar 2003 14:36:47 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: any simple way to detect the real end of a command in a perl script?
Message-Id: <3e691eff@news.victoria.tc.ca>
Abigail (abigail@abigail.nl) wrote:
: mkkwong (mkwong@wideopenwest.com) wrote on MMMCDLXXV September MCMXCIII
: in <URL:news:4977b250.0303071150.3bde08f6@posting.google.com>:
: {} I intend to write some simple tools to help myself in writing perl
: {} programs. The tool will read a perl script and analyze the content and
: {} perhaps generate some useful information.
: This is a very hard problem. There are some modules in the B::
: namespace that do stuff like that, but they were written by some
: very clever minds, with lots and lots of deep knowledge of the
: Perl internals.
: {} One of the first problems I encounter is to figure out whether a ;
: {} found in a line in the script is really the end of a command. A
: {} similar problem is how can we tell the end of those commands that may
: {} not end in a ; (like the last statement in a block).
: {}
: {} Obviously the perl debugger or the useful perltidy() utility has this
: {} capabilty. I am way too lazy (aka don't know enough) to try to dig
: {} into those to find out how they do it. I don't really need the full
: {} power like those tools to parse the complete perl syntax - it is
: {} enough if I can simply determine that the ; I see is not part of a
: {} string value, or part of a here doc, or a regex, or a comment etc.
: The only way to do that is by parsing Perl. Any heuristic you can come
: up with that doesn't involve parsing Perl, I can find an example that
: fails.
: {} Similarly, if I see an enclosing }, how do I know whether that is the
: {} end of a code block and not part of a hash notation, or part of a
: {} string value, or a here doc or a regex, etc.
: You will have to parse Perl. Note that even perl itself doesn't always
: guess right whether a '{' starts a code block, or a hash reference.
One way to do this sort of thing is to split on the thing that might be
the end (`;' in your case) and then eval each piece, adding back the
pieces until eval doesn't complain.
I'll leave it to the imagination how to usefully use this, though.
------------------------------
Date: Fri, 07 Mar 2003 20:17:36 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Can I Get Neater Hyperlinks in Emails
Message-Id: <mbudash-FCE14C.12173507032003@typhoon.sonic.net>
In article <20030307.154625.1665947468.1022@richg.zync>,
"Richard Gration" <richard@zync.co.uk> wrote:
> To get what you want you need to be sending out HTML emails. Putting aside
> for the moment the fact that this is the devil's work, you need to read
> the RFCs pertaining to the format of HTML emails and then adjust the code
> to compose them. Composing HTML emails is not totally straightforward,
curious - what's not straightforward about it? change the content-type
to text/html and you're off...?
> however the perl code to implement the process is, relatively.
>
> Do your emails work?? If so, don't turn them into HTML.
it is a common business requirement, however, in today's world to send
out multipart/alternative emails containg both text/plain and text/html
versions of a message.
just my .02
hth-
------------------------------
Date: Fri, 7 Mar 2003 20:12:26 -0000
From: "Geoff Soper" <geoff.news7@alphaworks.co.uk>
Subject: Catching errors using DBI
Message-Id: <3e68fd31$0$6294$cc9e4d1f@news.dial.pipex.com>
I'm using DBI to access a MySQL database. There are times when it is
possible that the queries I'm executing won't return a result, how can I
catch this in the example of the code below, i.e. when there is no
user_cookie corresponding to the username?
Many thanks
Geoff
# Get cookie value from database and set up cookie
my $cookie_value = $dbh->selectrow_array( "SELECT user_cookie FROM users
WHERE username = ?",
{},
param("username"));
my $cookie = cookie(-name => 'user',
-value => $cookie_value);
------------------------------
Date: Fri, 07 Mar 2003 20:32:38 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Catching errors using DBI
Message-Id: <mbudash-BAC1E9.12323707032003@typhoon.sonic.net>
In article <3e68fd31$0$6294$cc9e4d1f@news.dial.pipex.com>,
"Geoff Soper" <geoff.news7@alphaworks.co.uk> wrote:
> I'm using DBI to access a MySQL database. There are times when it is
> possible that the queries I'm executing won't return a result, how can I
> catch this in the example of the code below, i.e. when there is no
> user_cookie corresponding to the username?
>
> Many thanks
> Geoff
>
> # Get cookie value from database and set up cookie
> my $cookie_value = $dbh->selectrow_array( "SELECT user_cookie FROM users
> WHERE username = ?",
> {},
> param("username"));
> my $cookie = cookie(-name => 'user',
> -value => $cookie_value);
>
>
IIUWYA, wrap your cookie() call like so:
if ($cookie_value) {
my $cookie = cookie(-name => 'user',
-value => $cookie_value);
}
hth-
------------------------------
Date: 07 Mar 2003 20:45:08 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Catching errors using DBI
Message-Id: <u9d6l252jv.fsf@wcl-l.bham.ac.uk>
"Geoff Soper" <geoff.news7@alphaworks.co.uk> writes:
> Subject: Catching errors using DBI
Look for the word "error" in the documentation of DBI.
> I'm using DBI to access a MySQL database. There are times when it is
> possible that the queries I'm executing won't return a result, how can I
> catch this in the example of the code below, i.e. when there is no
> user_cookie corresponding to the username?
> # Get cookie value from database and set up cookie
> my $cookie_value = $dbh->selectrow_array( "SELECT user_cookie FROM users
> WHERE username = ?",
> {},
> param("username"));
> my $cookie = cookie(-name => 'user',
> -value => $cookie_value);
It is not an error for an SQL query to return an empty responses.
You can test if $cookie_value is defined using the function of that
name.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 7 Mar 2003 21:30:29 -0000
From: "Geoff Soper" <geoff.news7@alphaworks.co.uk>
Subject: Re: Catching errors using DBI
Message-Id: <3e690f7b$0$6299$cc9e4d1f@news.dial.pipex.com>
"Michael Budash" <mbudash@sonic.net> wrote in message
news:mbudash-BAC1E9.12323707032003@typhoon.sonic.net...
> In article <3e68fd31$0$6294$cc9e4d1f@news.dial.pipex.com>,
> "Geoff Soper" <geoff.news7@alphaworks.co.uk> wrote:
>
> > I'm using DBI to access a MySQL database. There are times when it is
> > possible that the queries I'm executing won't return a result, how can I
> > catch this in the example of the code below, i.e. when there is no
> > user_cookie corresponding to the username?
> >
<snip>
>
> IIUWYA, wrap your cookie() call like so:
>
> if ($cookie_value) {
> my $cookie = cookie(-name => 'user',
> -value => $cookie_value);
> }
>
Thanks for that, quite obvious now you point it out, it's not an error, just
a particular kind of success!
Thanks very much
------------------------------
Date: Fri, 7 Mar 2003 12:06:37 -0600
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: CGI query string help
Message-Id: <b4anbh$rj6$1@slb0.atl.mindspring.net>
"Peter Cooper" <newsfeed2@boog.co.uk> wrote in message
news:YZ1aa.15910$EN3.128294@newsfep4-glfd.server.ntli.net...
> > #!/usr/local/bin/perl
> >
> > use strict;
> > use CGI qw(:standard);
> >
> > $user_name = $query->param('name');
>
> Perhaps I'm missing something, as this is not mentioned in the other
replies..
Yes, you missed the earlier mention of it.
From an earlier message:
my $user_name = param('name');
my $user_age = param('age');
# removed undefined CGI object $query
> but shouldn't you actually create an instance of the class with .. << my
$query
> = new CGI; >> first?
Yes, if you wish to be able to use it.
> Or is $query exported anyway?
No.
Cheers.
Bill Segraves
------------------------------
Date: 7 Mar 2003 08:28:12 -0800
From: martin.doelle@is-sw.com (martin)
Subject: event notification Perl - Windows
Message-Id: <e152ed78.0303070445.6341d484@posting.google.com>
Hi there!
is there a possibility to receive events from the windows operating
system, when a dialog box of a windows application is created, so that
windows will notify my perl script that an event occured.
thx for your help!
martin
------------------------------
Date: 07 Mar 2003 21:23:11 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Floyd-Warshall on undirected graph?
Message-Id: <slrnb6i3du.r9j.abigail@alexandra.abigail.nl>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMCDLXXV
September MCMXCIII in <URL:news:b49n5h$hct$1@mamenchi.zrz.TU-Berlin.DE>:
%% Alexandros <a_valarakos@hotmail.com> wrote in comp.lang.perl.misc:
%% > Hello,
%% >
%% > i tried to apply APSP_Floyd_Warshall on a undirected graph but i didn't get
%%
%% What is "APSP_Floyd_Warshall"? The one Perl implementation I know
%% of is Abigail's Algorithm::Graphs::TransitiveClosure.
%%
%% > the expected output. Then i realised that the algorith should be applied on
%% > a direxted graph.
%% > Is it possible to overcome this prob.?
%%
%% Usually an undirected graph is represented as a directed graph with
%% (directed) vertices going in both directions. A Floyd_Warshall
%% implementation should be able to deal with both.
There's isn't any point in applying Floyd Warshall on a directed
graph. Floyd Warshall is a cubic algorithm.
If you want to calculate the transitive closure of an undirected
graph, all you need is find the connected parts of the graph.
Which you can do in linear time, IIRC.
Abigail
--
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
print } sub __PACKAGE__ { &
print ( __PACKAGE__)} &
__PACKAGE__
( )
------------------------------
Date: 07 Mar 2003 22:02:03 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Floyd-Warshall on undirected graph?
Message-Id: <slrnb6i5mr.r9j.abigail@alexandra.abigail.nl>
Abigail (abigail@abigail.nl) wrote on MMMCDLXXV September MCMXCIII in
<URL:news:slrnb6i3du.r9j.abigail@alexandra.abigail.nl>:
__
__
__ There's isn't any point in applying Floyd Warshall on a directed
^^ undirected
__ graph. Floyd Warshall is a cubic algorithm.
__
__ If you want to calculate the transitive closure of an undirected
__ graph, all you need is find the connected parts of the graph.
__
__ Which you can do in linear time, IIRC.
__
__
__
__ Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
------------------------------
Date: 7 Mar 2003 09:18:18 -0800
From: naihuis@gmx.de (mbuechner)
Subject: foreach in while-block cancels while
Message-Id: <210a2e30.0303070635.6920dfff@posting.google.com>
hi,
i´m trying to check, if a certain process is running on my w2k-server.
if it isn´t, perl should delete a special file. the script should run
as a service and do the check every 60 secounds.
use Win32::Process::Info;
while ( 1 eq 1 ) {
$sdf = 0;
my $pi = Win32::Process::Info->new ();
foreach $proc ($pi->GetProcInfo ()) {
foreach ($proc) {
if ($proc->{Name} eq "saplgpad.exe") {
$sdf = 1;
}
}
}
if ($sdf eq 0){
if ( -e "c:\\perl\\test\\check.txt") {
unlink 'c:\\perl\\test\\check.txt';
}
}
sleep 60;
}
not very elegant (forgive me, i´m complete new to perl), but not very
complicated either. but when i start the script something strange
happens.
when i start it by double-click in windows, it runs one time and then
dies. when i start it from the command-line, it runs two times and
then dies. but it never runs the way it should, infinite.
i´m thankful for any suggestions to get this thing running!!
bye
matthias
------------------------------
Date: Fri, 07 Mar 2003 19:10:19 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: foreach in while-block cancels while
Message-Id: <pan.2003.03.07.18.05.49.370324@aursand.no>
On Fri, 07 Mar 2003 09:18:18 -0800, mbuechner wrote:
> use Win32::Process::Info;
>
> while ( 1 eq 1 ) {
>
> $sdf = 0;
>
> my $pi = Win32::Process::Info->new ();
> foreach $proc ($pi->GetProcInfo ()) {
> foreach ($proc) {
> if ($proc->{Name} eq "saplgpad.exe") {
> $sdf = 1;
> }
> }
> }
>
> if ($sdf eq 0){
> if ( -e "c:\\perl\\test\\check.txt") {
> unlink 'c:\\perl\\test\\check.txt';
> }
> }
> sleep 60;
> }
Hmm. I think I would have written the script slightly differently:
#!/usr/bin/perl
#
use strict;
use warnings;
use Win32::Process::Info;
while ( 1 ) {
my $pi = Win32::Process::Info->new();
foreach my $proc ( $pi->getProcInfo() ) {
if ( $proc{'Name'} eq 'saplgpad.exe' ) {
if ( -e 'c:\\perl\\test\\check.txt' ) {
unlink 'c:\\perl\\test\\check.txt';
}
last;
}
}
sleep( 60 );
}
This should work, AFAIK. A few tips for you:
o Don't use 'eq' or 'ne' to compare numerical values. You
have '==' and '!=' for that. See 'perldoc perlop'.
o 'last' jumps out of the current loop, as if you've already
reached the end.
o When checking for a TRUE or FALSE value, you don't need to
specify what is what, as you can't override Perl's builtin
values anyhow.
In this script, you can actually forget about the '$sdf' variable, thanks
to 'last'.
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: Fri, 07 Mar 2003 18:43:40 -0000
From: "W. Citoan" <wcitoan@NOSPAM-yahoo.com>
Subject: Re: foreach in while-block cancels while
Message-Id: <slrnb6hq2q.1r7.wcitoan@wcitoan-via.supernews.com>
On Fri, 07 Mar 2003 19:10:19 +0100, Tore Aursand wrote:
>
> Hmm. I think I would have written the script slightly differently:
>
> #!/usr/bin/perl
> #
> use strict;
> use warnings;
> use Win32::Process::Info;
>
> while ( 1 ) {
> my $pi = Win32::Process::Info->new();
> foreach my $proc ( $pi->getProcInfo() ) {
> if ( $proc{'Name'} eq 'saplgpad.exe' ) {
> if ( -e 'c:\\perl\\test\\check.txt' ) {
> unlink 'c:\\perl\\test\\check.txt';
> }
> last;
> }
> }
> sleep( 60 );
> }
This will do the opposite of what the OP wants. It will delete the file
if the process is found. The OP wants to delete it if it's not found.
I'd recommend something like:
#!/usr/bin/perl
#
use strict;
use warnings;
use Win32::Process::Info;
while ( 1 ) {
my $pi = Win32::Process::Info->new();
unless ( grep /saplgpad.exe/, $pi->getProcInfo() ) {
if ( -e 'c:\\perl\\test\\check.txt' ) {
unlink 'c:\\perl\\test\\check.txt';
}
}
sleep( 60 );
}
I'm not on a Windows machine so can't test it. If $pi->getProcInfo()
returns an array reference vs an array, you might need to adapt it, but
the logic would remain the same.
- W. Citoan
--
Simplicity does not precede complexity, but follows it.
------------------------------
Date: Fri, 07 Mar 2003 17:45:38 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: I want to know the line n umber of the error !
Message-Id: <pan.2003.03.07.16.06.01.658784@aursand.no>
On Fri, 07 Mar 2003 11:05:04 +0000, Helgi Briem wrote:
>> Funny as it is, though; I myself requested a lightweight CGI
>> replacement earlier today. *g*
> There are certainly plenty of those around.
>
> CGI::Simple;
Last updated: 09-Nov-2002
> CGI::Minimal;
Last updated: 10-Apr-2002
> CGI::Request;
Last updated: Didn't find this one...?
Anyway; Which one of these do you prefer?
> But as pointed out, you'd be *far* better off with a CGI replacement in
> the web server itself, like mod_perl or SpeedyCGI if the execution speed
> actually matters.
Yeah, especially when I'm _not_ so lucky to choose the setup of the web
server. :-/
For the n'th time: I _know_ how to make my application as fast as
possible; Use Apache and mod_perl. That's not my point, however; I want
to make my application go _as fast as possible_ without such luxury.
:)
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: Fri, 07 Mar 2003 17:45:38 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: I want to know the line n umber of the error !
Message-Id: <pan.2003.03.07.16.10.55.128283@aursand.no>
On Fri, 07 Mar 2003 08:35:09 -0500, Eric Osman wrote:
>> Of course not. I haven't seen anyone in this newsgroup calling anyone
>> stupid. But I myself have _almost_ called a certain way to do a thing
>> stupid at least a few times. :)
> Abigail called me a bonehead.
I'm from Norway, and you can't expect me to know that bonehead is the same
as stupid. Is it? :)
But - AFAIR - he called you that for a very good reason, didn't he?
> [...]
> ok, now you tell me, is this a lab exercise or production code ????
Production code, of course. But do you remember what your problem was in
the beginning of this thread?
"How can I convince the server to tell me what line number it
detects my PERL error on?"
And we _have_ answered this for you. Many times. Let me repeat myself:
Perl _does_ tell the _web server_ (which is handling the request) on what
line the error occured on.
So, if this still doesn't answer your problem, it's no longer a Perl
problem.
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: Fri, 07 Mar 2003 21:59:38 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: I want to know the line n umber of the error !
Message-Id: <b4b17j$1uk0tr$1@ID-184292.news.dfncis.de>
Tore Aursand wrote:
> But do you remember what your problem was in
> the beginning of this thread?
>
> "How can I convince the server to tell me what line number it
> detects my PERL error on?"
>
> And we _have_ answered this for you. Many times. Let me repeat myself:
> Perl _does_ tell the _web server_ (which is handling the request) on what
> line the error occured on.
>
> So, if this still doesn't answer your problem, it's no longer a Perl
> problem.
Err.. There _is_ an easily accomplished 'Perlish' way to tell the server
to make that info available to you, even if you cannot access the server
logs:
http://www.perldoc.com/perl5.8.0/lib/CGI/Carp.html#REDIRECTING-ERROR-MESSAGES
ASFAIU, this solution addresses Eric's initial question _directly_.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
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 4681
***************************************