[21900] in Perl-Users-Digest
Perl-Users Digest, Issue: 4104 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 12 14:07:14 2002
Date: Tue, 12 Nov 2002 11:05:12 -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 Tue, 12 Nov 2002 Volume: 10 Number: 4104
Today's topics:
Re: A vision for Parrot <donal.k.fellows@man.ac.uk>
Re: A vision for Parrot <donal.k.fellows@man.ac.uk>
Re: A vision for Parrot <nem00u@cs.nott.ac.uk>
Re: emailing files with perl <Graham.T.Wood@oracle.com>
Re: emailing files with perl (Tad McClellan)
Re: fetch all the bouncing e-mailaddresses (Tad McClellan)
Re: fetch all the bouncing e-mailaddresses <nobody@dev.null>
Re: fetch all the bouncing e-mailaddresses news@roaima.freeserve.co.uk
FYI: Perl required for MS Shared Source CLI <noemail@nowhere.net>
Re: Global file search function? (Bryan Castillo)
Re: Global file search function? <tk@WINDOZEdigiserv.net>
How much memory a perl process consume (TD)
how to debug anonymous functions (Raj)
Re: illegal use of comment ? (Kevin Cline)
Re: LWP-download help (Chris Liu)
Re: Newbie script needs help (Tad McClellan)
Re: Newbie script needs help (Tad McClellan)
Re: Newbie script needs help (robertbu)
Re: Newbie with Perl <krahnj@acm.org>
Re: Newbie with Perl (ebchang)
Re: perl daemon in windows memory hog ? <bowman@montana.com>
Re: perl daemon in windows memory hog ? <flying_dragon@china.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 12 Nov 2002 15:30:07 +0000
From: "Donal K. Fellows" <donal.k.fellows@man.ac.uk>
Subject: Re: A vision for Parrot
Message-Id: <3DD11E7F.C12E708A@man.ac.uk>
Benjamin Goldberg wrote:
> Considering that Jcl and Jython exist, it seems like a reasonable goal
(JCL is something else. I'd rather not remember it thankyouverymuch.)
> would be to make an interpreter which turns Java's .class files into
> Parrot .pasm files. Once that tool exists, one could simply translate
> Jcl and Jython into parrot... there would be no need to re-implement
> them.
>
> And one day, in the distant future, there will be a Perl6 decompiler,
> which will turn Parrot bytecode into Perl6. Then we'll be able to
> convert the translated Jython and Jcl into Perl6 :)
$10 says that only ever happens with a performance hit. The problem is that not
all bytecodes are created equal. (And Jacl is an implementation of Tcl in Java
more in the way that the usual form of Tcl is an implementation of the language
in C. The fact that Java uses bytecodes is pretty much just a distraction
here. We also have another way of integrating Tcl with Java that keeps Tcl
implemented in C, but which integrates almost identically with the Java
language.)
> > This sort of thing tends to make me suspicious that this is little
> > more than a pipe-dream, well, at least as far as Tcl's concerned. (I
> > don't know the other languages nearly well enough to comment in a
> > useful way.)
[...]
> Assuming you thouroughly understand Tcl's bytecodes, why not take a look
> at Parrot, and see whether the set of bytecodes that parrot supports is
> sufficient to do everything that Tcl's bytecodes do?
I know a bit about Tcl bytecodes, and a key factor about them is that they are
very tightly targetted towards implementing Tcl.
Hmm. A quick scan through the documentation doesn't really raise my hopes. Or
even leave me with a deep enough understanding of what's going on; is there any
deeper description than http://www.parrotcode.org/docs/parrot_assembly.pod.html
about? (OK, Tcl's bytecodes need documentation too, but I've already gone to
the effort to understand those as part of my maintenance and development
duties. I've just not got enough hours in the day.) Unfortunately, the bits
that I'm most interested in seem to be the bits with least info (isn't that
always the way with complex software systems?)
First impressions: what is meant by "string" anyway? Character sequence? Byte
sequence? UTF-8 sequence? ISO 8859-1 sequence? [FX: Reads docs] Oh, they
carry about what their encoding is with them? That must make working with them
fun. How does it handle things like the blecherous monstrosities[*] used for
system encodings in the Far East? On a quite separate point, is there a
strncmp() equivalent? That would make implementing Tcl much easier...
More generally, Tcl would need to use PMCs throughout. The problem is that
Tcl's value semantics (copy-on-write) do not line up well with that which Parrot
seems to use (object-based) and which, IIRC from the discussions at the time
when Parrot was being created, are closely based on those used in Perl even if
not precisely coincident. Hence we'd be unable to use ground values except as
part of the implementation of higher-level concepts. That'll impact badly on
performance.
It's at this point that I feel a round of "Stuff it. I'll stick to implementing
in C." coming on. I've been quietly watching Parrot for a while now, and I
still don't think that implementing Tcl in it is really a winning proposition.
I'd love someone to prove me wrong, but proof is building a Tcl interpreter in
or on top of Parrot and running the Tcl test suite on it (and getting a decent
proportion of the tests passing.)
BTW, how does Parrot handle calls to foreign code? The docs I've seen are on
the hazy side, and integration with existing C, C++ and FORTRAN monoliths is
(alas) all too important in particularly commercial development.
Donal.
[* The cluster of things known as "Shift-JIS" justifies this term. IMHO. ]
--
Donal K. Fellows http://www.cs.man.ac.uk/~fellowsd/ donal.fellows@man.ac.uk
-- The small advantage of not having California being part of my country would
be overweighed by having California as a heavily-armed rabid weasel on our
borders. -- David Parsons <o r c @ p e l l . p o r t l a n d . o r . u s>
------------------------------
Date: Tue, 12 Nov 2002 16:08:53 +0000
From: "Donal K. Fellows" <donal.k.fellows@man.ac.uk>
Subject: Re: A vision for Parrot
Message-Id: <3DD12795.23E2F02F@man.ac.uk>
Benjamin Goldberg wrote:
> The set of bytecodes which Parrot will be using has been decided, and
> while it's not fixed in stone, it's quite unlikely to get a whole other
> language's bytecodes added to it.
OK, let's go for a more concrete question. What sequence of bytecodes would let
me open a socket and talk to a remote host? The Parrot I/O operation opcodes
don't mention anything about sockets and nor can I tell how I would invoke a
piece of helper C or C++ to do the job on my behalf.
Donal.
--
Donal K. Fellows http://www.cs.man.ac.uk/~fellowsd/ donal.fellows@man.ac.uk
-- The small advantage of not having California being part of my country would
be overweighed by having California as a heavily-armed rabid weasel on our
borders. -- David Parsons <o r c @ p e l l . p o r t l a n d . o r . u s>
------------------------------
Date: Tue, 12 Nov 2002 17:10:53 +0000
From: Neil Madden <nem00u@cs.nott.ac.uk>
Subject: Re: A vision for Parrot
Message-Id: <LRaA9.1325$J55.292310@newsfep2-win.server.ntli.net>
Donal K. Fellows wrote:
<snip interesting discussion, which mostly goes over my head :>
>
> BTW, how does Parrot handle calls to foreign code? The docs I've seen are on
> the hazy side, and integration with existing C, C++ and FORTRAN monoliths is
> (alas) all too important in particularly commercial development.
>
On this particular point; has anyone thought of writing a unified C-API for Tcl,
Perl, Python, Ruby, (Java) etc? What I mean by this is that each of these
languages can be extended in C, and quite often are. Also, whenever I see
interesting new C/C++ libraries implemented, I also tend to see seperate
language bindings for each of these languages. This seems like a massive
duplication of effort. Would it be possible to abstract over the C API's of
these languages to a common core of functionality which all share (e.g. getting
an interpreter handle, registering a command, setting a variable etc)? I have
only dealt with Tcl's C interface, so this may be too difficult, but it seems
like it would be a huge step forward.
In terms of problems implementing this, I can see several problems:
1. Method of calling C-coded procedures. In Tcl, arguments are passed to C
procedures as Tcl_Obj's. Obviously this would be different for Perl or Python.
Is it possible to come up with an API which can convert to the appropriate
object type, or to some intermediate type?
2. Accessing functions which are not present in all languages. I'm sure there
are API's in Tcl which only make sense with respect to Tcl, and probably the
same in the other languages. So, how would one create a general API which
allows you to call language specific APIs? In the same way one handles platform
specific APIs?
3. Versioning. Which language versions are compatible with which abstract API? I
can see this one becoming insane over time. However, there are people with much
more experience with these issues than me, so there might be a way.
4... probably more, this is all coming of the top of my head.
Hmm.. the more I think about this, the more problems it seems to present. I'd
love to be able to write an extension, and have it instantly work with x
different langauges. Also, I'd love to be able to use Python and Perl
extensions from Tcl, without loading seperate interpreters and all that. Am I
dreaming of an impossible Utopia?
Neil "soo naive" Madden
--
package r Tkhtml;package r http;pack [scrollbar .v -o v -co {.h yv}] -s right\
-f y;pack [html .h -ys {.v set}] -f both -e 1;bind .h.x <1> {eval g [.h href %x\
%y]};proc g u {set t [http::geturl $u];.h cl;.h p [http::data $t];http::cleanup\
$t;.h co -base $u};g http://mini.net/tcl/976.html;proc bgerror args {};# NEM :-)
------------------------------
Date: Tue, 12 Nov 2002 15:51:35 +0000
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: emailing files with perl
Message-Id: <3DD12387.25D4EC7E@oracle.com>
See answers provided to "emiling files with perl". The problem is that your
filehandle on your close statement is spelt wrong so the file is not closed.
Graham
------------------------------
Date: Tue, 12 Nov 2002 10:12:16 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: emailing files with perl
Message-Id: <slrnat2a30.3j5.tadmc@magna.augustmail.com>
ddineen.cs@clearstream.com <ddineen.cs@clearstream.com> wrote:
> When I
> run the program I get no errors
If you had asked perl to warn you about common problems, it
would have warned you about your common problem.
You should always enable warnings when developing Perl code.
Warnings would have pointed out the problem in milliseconds.
> open(TSDREQUEST,">../TSDRequests/CodeSigning/$refnum.req") || die
^^^^^^^^^^
> close(TSDREQUESTS);
^^^^^^^^^^^
One of these things is not like the other,
one of these things just isn't the same...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 12 Nov 2002 07:14:19 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: fetch all the bouncing e-mailaddresses
Message-Id: <slrnat1vlb.346.tadmc@magna.augustmail.com>
Leif Wessman <leifwessman@hotmail.com> wrote in upside-down style:
> Andras Malatinszky <nobody@dev.null> wrote in message news:<3DCFCCAD.60703@dev.null>...
>> Leif Wessman wrote:
>>
>> >[...] I want to go thru all the bounce-mails and fetch all occurrences
>> > of e-mailadresses like this:
>> > while ($line = <IN>) {
>> > if ($line =~ /^[a-zA-Z0-9\-\._]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/)
>> > {
>> > print $1;
>> > But the problem is that $1 does not contain anything at any point.
>> $1 will contain whatever the sub-regex within the first pair of
>> parantheses matches.
> Thank you for your answer. My main question is still unanswered: How
> do I do it so that I can fetch the address only
Put parenthesis around the part of the pattern that correspond
to the "email address", then reference the correct dollar-digit
variable.
But in this case, since you have both ends anchored, you can
print $line instead of $1.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 12 Nov 2002 15:11:19 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: fetch all the bouncing e-mailaddresses
Message-Id: <3DD119E2.2020805@dev.null>
Tad McClellan wrote:
> Leif Wessman <leifwessman@hotmail.com> wrote in upside-down style:
>
>>Andras Malatinszky <nobody@dev.null> wrote in message news:<3DCFCCAD.60703@dev.null>...
>>
>>>Leif Wessman wrote:
>>>
>>>
>>>>[...] I want to go thru all the bounce-mails and fetch all occurrences
>>>>of e-mailadresses like this:
>>>>
>
>
>>>>while ($line = <IN>) {
>>>> if ($line =~ /^[a-zA-Z0-9\-\._]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/)
>>>>{
>>>> print $1;
>>>>
>
>
>>>>But the problem is that $1 does not contain anything at any point.
>>>>
>
>>>$1 will contain whatever the sub-regex within the first pair of
>>>parantheses matches.
>>>
>
>>Thank you for your answer. My main question is still unanswered: How
>>do I do it so that I can fetch the address only
>>
>
>
> Put parenthesis around the part of the pattern that correspond
> to the "email address", then reference the correct dollar-digit
> variable.
>
> But in this case, since you have both ends anchored, you can
> print $line instead of $1.
>
Minor detail: you probably want to chomp before that.
I almost added the suggestion Tad made to my original answer, but then I
realized I was not really sure what the OP's objective is. Do we have a
single file that lists all the e-mail addresses that bounced? If so,
then Tad's suggestion works fine, but ... what's the point of the whole
exercise? Or do we instead have a bunch of e-mail *messages* letting us
know that a message we sent did not make it to the intended recipient?
If that's the case, you need to do put parens around the entire regex
that is supposed to match the e-mail addresses and then look at $1. But
then you will get a lot of postmaster@domain.com-type addresses, and
there is no guarantee that the intended recipients address is mentioned
in the bounce message at all.
------------------------------
Date: Tue, 12 Nov 2002 17:31:57 +0000
From: news@roaima.freeserve.co.uk
Subject: Re: fetch all the bouncing e-mailaddresses
Message-Id: <dudrqa.kf2.ln@moldev.cmagroup.co.uk>
testversion1 <testversion1@excite.com> wrote:
> The only characters that i'm aware of that are not allowed for
> sure are commas, another @ sign, and your group of spaces and the
> like. Anyone else know what other characters are absolutely not
> allowed?
Spaces are permitted in usernames provided the entity is surrounded
with double quote marks. For example, each of the following two lines
are valid and deliverable email addresses:
"Spam is not welcome here"@roaima.freeserve.co.uk
"No spam @ here"@roaima.freeserve.co.uk
I'm fairly sure both will break your regular expression.
Chris
--
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}
------------------------------
Date: 12 Nov 2002 14:28:48 GMT
From: nobody <noemail@nowhere.net>
Subject: FYI: Perl required for MS Shared Source CLI
Message-Id: <Xns92C460ED17446abccbaabc@216.148.53.81>
Just FYI-
From MS's "Shared Source CLI 1.0 Release"
(.NET Framework's Common Language Infrastructure)
( http://msdn.microsoft.com/downloads/default.asp
?url=/downloads/sample.asp
?url=/MSDN-FILES/027/002/097/msdncompositedoc.xml )
"System Requirements
On Windows you will need:
Windows XP or Windows 2000. We recommend Windows XP.
Microsoft Visual Studio .NET.
Perl 5.6 (available from http://www.perl.org.)
Archiving utility of choice—WinZip or other.
256 MB of memory.
One gigabyte of free disk space."
I think Perl is used as part of the build process.
I don't recall MS every _requiring_ Perl before.
------------------------------
Date: 12 Nov 2002 07:40:21 -0800
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: Global file search function?
Message-Id: <1bff1830.0211120740.2ffeab8e@posting.google.com>
> |
> | There is ofcourse the GNU "locate" command. Perhaps already installed on
> | your system...
>
> WHy on earth would you want to use a system call when you can do it
> quite as easily in Perl that's portable?
>
>
> tk
The locate program uses an indexed database (at least the
implementations I know of). It will be alot faster than File::Find.
Too bad locate hasn't been complete d yet, for Perl Power Tools.
------------------------------
Date: Tue, 12 Nov 2002 15:52:25 GMT
From: tk <tk@WINDOZEdigiserv.net>
Subject: Re: Global file search function?
Message-Id: <2t82tuos0tgoohdn3sjd3mo9aivlh192kk@4ax.com>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
In a fit of excitement on 12 Nov 2002 07:40:21 -0800,
rook_5150@yahoo.com (Bryan Castillo) managed to scribble:
| > |
| > | There is ofcourse the GNU "locate" command. Perhaps already
| > | installed on your system...
| >
| > WHy on earth would you want to use a system call when you can do it
| > quite as easily in Perl that's portable?
| >
| >
| > tk
|
| The locate program uses an indexed database (at least the
| implementations I know of). It will be alot faster than File::Find.
| Too bad locate hasn't been complete d yet, for Perl Power Tools.
[d:\home\tk]$ locate
'locate' is not recognized as an internal or external command,
operable program or batch file.
Kind of leaves me screwed, if I tried to run the script on this box.
As I said, system() isn't portable.
Regards,
tk
-----BEGIN xxx SIGNATURE-----
Version: PGP Personal Privacy 6.5.3
iQA/AwUBPdEj+SjNZg8h4REKEQL8FgCfWQ9zy8sll/mO6LWcKpR1OFIW4tMAmwWa
qOk4apPjsLrFcZZuVbI3CMMT
=dEtd
-----END PGP SIGNATURE-----
--
+--------------------------+
| digiServ Network |
| Web solutions | Remove WINDOZE to reply.
| http://www.digiserv.net/ |
+--------------------------+
------------------------------
Date: 12 Nov 2002 06:09:34 -0800
From: tushar08@yahoo.com (TD)
Subject: How much memory a perl process consume
Message-Id: <584a8362.0211120609.15c3788a@posting.google.com>
Hello all,
When Perl can tell its PROCESS ID ( $$ ), why it is difficult to tell
how much memory this PROCESS ID is consuming??
I have some memory leak in my programs. After reading
http://www.perldoc.com/perl5.6/pod/perldebguts.html, for me it does
not seem easy because I have too many perl classes.
is there any Module in Perl or any system function in Perl or OS level
function -- that can tell me how much memory it has consumed ( say
getmemoryusage($$) or similar )
I am running Perl 5.6 Build 631 on a windows 2000 server.
Thanks
Tushar
------------------------------
Date: 12 Nov 2002 10:53:36 -0800
From: raj@tao.ca (Raj)
Subject: how to debug anonymous functions
Message-Id: <feea11ef.0211121053.196e2dfc@posting.google.com>
Hi all!
does anyone know if this is possible? If yes, do you know how
I would go about setting a breakpoint and step through the code?
I believe I tried it in the past and it didn't work. But I have
not definitively verified this.
Thanks for any help!
--Raj
------------------------------
Date: 12 Nov 2002 09:32:58 -0800
From: kcline17@hotmail.com (Kevin Cline)
Subject: Re: illegal use of comment ?
Message-Id: <ba162549.0211120932.6336fb23@posting.google.com>
Benjamin Goldberg <goldbb2@earthlink.net> wrote in message news:<3DD0038E.B33E668C@earthlink.net>...
Eg, reading across the top of my keyboard, I would
> say tilde, exclamation point, at symbol, pound sign, dollar sign,
> percent sign, caret, ampersand, times (only when used to multiply things
> together, otherwise it's "asterix"),
"asterisk".
------------------------------
Date: 12 Nov 2002 06:44:34 -0800
From: fcqmax@pchome.com.tw (Chris Liu)
Subject: Re: LWP-download help
Message-Id: <806277c.0211120644.2e477ebd@posting.google.com>
fcqmax@pchome.com.tw (Chris Liu) wrote in message news:<806277c.0211120020.8bfb3b3@posting.google.com>...
> Somehow lwp-download doesn't recognize the variables in the URL string
> when I use the GET method. Any advice? Thanks.
>
> a perl newbie
duh...ok, I'm one step up a newbie.. lwp-download doesn't recognize
get url strings...
This works well enough...
use LWP::Simple;
getstore($URL, $FILE);
------------------------------
Date: Tue, 12 Nov 2002 08:08:47 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Newbie script needs help
Message-Id: <slrnat22rf.346.tadmc@magna.augustmail.com>
al <al@onetel.net.uk> wrote:
> I'm new to Perl and could use some help
> #!/usr/bin/perl
Ask for all the help you can get:
#!/usr/bin/perl
use warnings;
use strict;
> $file = 'qa.db' ; # Name the file
> open(INFO, "<$file" ) ; # Open the file
You should always, yes *always*, check the return value from open():
open INFO, $file or die "could not open '$file' $!";
> @lines = <INFO> ; # Read it into an array
> close(INFO) ; # Close the file
There is no need to store all of the lines in memory only to
loop over each one.
You can simply loop over each line, process it, and get the next
line, never needing to have more than a single line in memory.
> print "Search string: " ;
> read STDIN, $search, 3, 0; #Prompt user for search string
The search string must be 3 characters long?
Where do you prompt for the field to be searched?
> if ($line =~ /^ $search/cis )
You should not put options on your pattern matches willy-nilly.
Do you understand what each of those options does?
You should not use options unless you know what they do.
The "c" and "s" are superfluous for the pattern you are using.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 12 Nov 2002 08:03:20 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Newbie script needs help
Message-Id: <slrnat22h8.346.tadmc@magna.augustmail.com>
al <al@onetel.net.uk> wrote:
> The program should pull in a comma-delimited text file called
> "qa.db". It should prompt the user for the string and which field to
> be searched. It should then search for a string by field
-------------------------------------
#!/usr/bin/perl
use warnings;
use strict;
print "Search string: " ;
chomp( my $search = <STDIN> );
print "Field number: " ;
chomp( my $field = <STDIN> );
$field--; # people start counting at one, arrays start at zero
my $file = 'qa.db' ; # Name the file
open INFO, $file or die "could not open '$file' $!";
while ( <INFO> ) {
my @f = split /,/;
print if $f[$field] =~ /$search/i;
}
close INFO;
-------------------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 12 Nov 2002 10:22:32 -0800
From: robertbu@hotmail.com (robertbu)
Subject: Re: Newbie script needs help
Message-Id: <8c7725ac.0211121022.5db535b7@posting.google.com>
>
> I have been able to pull in qa.db but cannot get the search routine to
> fly. Any ideas?
I'm fairly new to perl, but I can point out a few things that
might be helpful to you.
As you suspect, your regular expression has problems. In
order to get something working, replace "/^ $search/cis"
with "/$search/i".
You might want to download regexEvaluater from:
http://home.arcor.de/clemens.giegerich/
You can load your file, apply regular expressions, and see
the matches (or not) visually.
As for searching on specific fields, perl provides a plathora
of solutions. The easiest place to start is to use split()
to pull apart each line into an array.
@fields = split ',', $line;
Note if your field data can contain a comma, this solution will
not work. For example, this solution breaks on a field
like: "10,237.23"
To handle that type of data, you can use the Text::Parse module,
or there is code in the Perl Cookbook. See Recipe 1.15
"Parsing Comma-Separate Data."
Other solutions for pulling out fields involve regular expressions.
For simpler ones, see the sections "Extracting Matches" and
"Matching repetitions" in perlretut.
== Rob ==
------------------------------
Date: Tue, 12 Nov 2002 14:33:13 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Newbie with Perl
Message-Id: <3DD11111.24F793D2@acm.org>
Michael J Wilusz wrote:
>
> Hey All!
> Great newgroup! It's hard to find one where everyone is down to Earth
> and not lookin to hurt eachother. Anyways... onto Perl. Never touched it,
> but must say I've heard a lot with Perl scripts and such. Here's what I
> need to do:
>
> -Take a filename as a command line argument.
> -The file will contain lines which are either a comment,
> beginning with the character #, or records of
> white-space-seperated fields of the format:
>
> -I will be using a remote file called names.dat as my input.
> -This file is a list of names (makes sense, right?)
> -The line's look like the following
> tldona TLD Tony
> L Danza 523-8426 Junior_Designer RO
> Here's what each means: Unix-username Initials Firstname MI Lastname
> Phone Site Attributes
>
> The output should l ook like this:
>
> Phone Book
>
> Name Telephone
> =============================
> Tony Danza 584 523 8426
>
> And here's a hint I was given:
> Hint: the first line of your script should be:
> #! /util/bin/perl -w
This should get you started:
#!/usr/bin/perl -w
use strict;
print "Name Telephone\n";
print '=' x 33, "\n";
while ( <> ) {
next if /^#/ or not /\S/;
printf "%-12s%-12s%9s\n", (split)[2,4,5];
}
__END__
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 12 Nov 2002 16:57:36 GMT
From: echang@netstorm.net (ebchang)
Subject: Re: Newbie with Perl
Message-Id: <Xns92C479BC28C75echangnetstormnet@207.106.92.86>
Michael J Wilusz <mjwilusz@acsu.buffalo.edu> wrote in
<aqpsff$5ff$1@prometheus.acsu.buffalo.edu>:
> Hey All!
> Great newgroup! It's hard to find one where everyone is down to
> Earth
> and not lookin to hurt eachother. Anyways... onto Perl. Never touched
> it, but must say I've heard a lot with Perl scripts and such. Here's
> what I need to do:
[snip]
>And here's a hint I was given:
> Hint: the first line of your script should be:
> #! /util/bin/perl -w>
>
> Any help would be awesome. I'm recently came out of emergency surgery
> and have work piled on me, and had a gentle reminder today that the
> deadline for this is upcoming. I have some minor Java knowledge, so
> basic programming is fresh in this young mind. Thanks for any and all
> help everyone! Good evening all.
Given the specificity of the problem description, the origin of your
article, and the terseness of the hint, I detect a homework assignment. I'll
offer some more hints.
First, read your Perl textbook and get copies of the class notes if you were
absent.
Second, do the following: print the heading; open the file (look up open in
the the text and also read the perlopentut documentation); read the lines
from the file (probably the same chapter in the text); split each line into
a list of the separate fields (did your instructor *really* say
"seperated?"); print out the designated fields, making the necessary
adjustment to the phone number; close the file.
Third, hope your instructor didn't read your attempt to get someone to write
your assignment for you.
--
EBC
------------------------------
Date: Tue, 12 Nov 2002 08:04:11 -0700
From: bowman <bowman@montana.com>
Subject: Re: perl daemon in windows memory hog ?
Message-Id: <aqr57e$cj9mh$1@ID-159066.news.dfncis.de>
Tan Nguyen wrote:
>
> The problem with SCManager is that for some reason IIS doesn't respond
> while it's still alive, thus SCManager still sees it as a functioning
> service. The only true test is sending HEAD requests to IIS to see if it
> responds. If not, you can use RPC calls to shut down the remote server or
> stop IIS service on the local box and restart it. I'm not sure if Win32
> Perl module will handle these nicely. It's not too hard to write this
> stuff in C++ using Win32 API. If memory serves me right, my stuff took
> less than 200 lines of code including emailing when detecting problematic
> server etc.
Good point. The monitor I wrote was watching a portmapper service, among
other things. The portmapper could be alive as far as the SCManager and
process list were concerned, and still not responsive, so I had to attempt
a connection as the ultimate test. I, too, did the final code in C++. I may
have been able to do it in Perl, but some of the API calls get into that
semi-documented area of Windows where you really want complete control.
------------------------------
Date: Tue, 12 Nov 2002 18:02:18 GMT
From: "James Q.L" <flying_dragon@china.com>
Subject: Re: perl daemon in windows memory hog ?
Message-Id: <KmbA9.45479$oRV.42866@news04.bloor.is.net.cable.rogers.com>
"Tan Nguyen" <nospam@nospam.com> wrote in message
news:3dd0bbfb$1_4@nopics.sjc...
>
> "bowman" <bowman@montana.com> wrote in message
> news:aqq70p$c8pc9$1@ID-159066.news.dfncis.de...
> > James Q.L wrote:
> > >
> > > now i need to write a script that monitor the IIS server state and
> restart
> > > it when necessary.
> > > i am going to use Win32::Daemon and leave it on all the time. but i am
> > > afraid that perl
> > > will eat much more memory and hog the server..
>
> Are you going to monitor several IIS servers or just one on a local box?
it's only running on one IIS server.
> > >
> > > if you have experience working on this. i would love to hear.
> > >
> I wrote a little monitor in C++ using Win32 API and SCManager to be able
to
> monitor the servers both locally and remotely.
>
> > I've never monitored the IIS server, but it is easy to query the
SCManager
> > periodically to get a services's state, and restart it if it isn't
> > running.You just need to sleep so the script isn't running a tight loop.
>
> The problem with SCManager is that for some reason IIS doesn't respond
while
> it's still alive, thus SCManager still sees it as a functioning service.
The
> only true test is sending HEAD requests to IIS to see if it responds. If
> not, you can use RPC calls to shut down the remote server or stop IIS
> service on the local box and restart it. I'm not sure if Win32 Perl module
> will handle these nicely. It's not too hard to write this stuff in C++
using
> Win32 API. If memory serves me right, my stuff took less than 200 lines of
> code including emailing when detecting problematic server etc.
what's the HEAD requests to IIS you refer to?..
here i post the code using Win32::Daemon.
use Win32::Daemon;
open ( OUT, '>>c:/iisMon/iis.log' ) || die ( "Unable to open file: $!" );
Win32::Daemon::StartService();
while ( SERVICE_STOPPED != ( $State = Win32::Daemon::State() ) )
{
if ( SERVICE_START_PENDING == $State )
{
print OUT "Starting Service\n";
Win32::Daemon::State( SERVICE_RUNNING );
}
elsif ( SERVICE_PAUSE_PENDING == $State )
{
print OUT "Pausing Service\n";
Win32::Daemon::State( SERVICE_PAUSED );
}
elsif ( SERVICE_CONTINUE_PENDING == $State )
{
print OUT "Resuming Service\n";
Win32::Daemon::State( SERVICE_RUNNING );
}
elsif ( SERVICE_STOP_PENDING == $State )
{
print OUT "Service Stopping\n";
Win32::Daemon::State( SERVICE_STOPPED );
}
elsif ( SERVICE_RUNNING == $State )
{
## under normal stage.
my @status = `iisreset /status`;
unless($status[1] =~ /: Running/) {
print OUT scalar localtime;
print OUT " Restarting IIS server\n";
`iisreset /restart /rebootonerror /timeout:60`;
}
}
sleep(5);
}
Win32::Daemon::StopService();
i want to log the iisreset command,
`iisreset /restart /rebootonerror /timeout:60`;
it will restart the IIS server, if it didn't response within 60 seconds then
the computer will get rebooted.
i want to save the log
my $log = `iisreset /restart /rebootonerror /timeout:60`;
print OUT $log;
is it possible to do it in this sequence or should i do it in
'SERVICE_STOP_PENDING' ?
and is the timeout setting too long ? and what's the max sleep time i can
set in Win32::Daemon ? i am afraid the SCM can't wait that long.
Regards,
James.Q.L
------------------------------
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 4104
***************************************