[24991] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 7241 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 13 18:07:07 2004

Date: Wed, 13 Oct 2004 15:05:09 -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           Wed, 13 Oct 2004     Volume: 10 Number: 7241

Today's topics:
    Re: [newbie] shtml question <usenet@morrow.me.uk>
    Re: [newbie] shtml question <noreply@gunnar.cc>
    Re: Acceptible idiom ? (Anno Siegel)
        amavisd-new perl patterns <spam.me@offizi.nl>
    Re: Concatenating an array into one string? <a@a.com>
    Re: Concatenating an array into one string? <1usa@llenroc.ude.invalid>
    Re: Concatenating an array into one string? <jurgenex@hotmail.com>
    Re: Creating a random uniqie directory <usenet@morrow.me.uk>
        function overloading in Perl (wana)
    Re: function overloading in Perl <postmaster@castleamber.com>
    Re: hard references/arrays <usenet@morrow.me.uk>
        How to package my perl scripts (that depend on other ut (Markus Dehmann)
        HTML::Parser and <p> behaviour? <geoff.cox@removethisplease.freeuk.com>
    Re: HTML::Parser and <p> behaviour? <1usa@llenroc.ude.invalid>
    Re: HTML::Parser and <p> behaviour? <geoff.cox@removethisplease.freeuk.com>
    Re: HTML::Parser and <p> behaviour? <bigal187@remove.rx.eastcoasttfc.com>
    Re: HTML::Parser and <p> behaviour? <1usa@llenroc.ude.invalid>
    Re: HTML::Parser and <p> behaviour? <1usa@llenroc.ude.invalid>
    Re: Lagrange Interpolating Polynomial <usenet@morrow.me.uk>
    Re: localizing %SIG handlers <usenet@morrow.me.uk>
    Re: Perl to monitor server stats <1usa@llenroc.ude.invalid>
    Re: Perl to monitor server stats <usenet@morrow.me.uk>
    Re: Perls system() call fails in a cgi-file running on  <usenet@morrow.me.uk>
        Restricting a program to one running instance <usenet@morrow.me.uk>
    Re: undef takes forever <usenet@morrow.me.uk>
    Re: Using a variable size with the repetition quantifie <usenet@morrow.me.uk>
        Win2k - Ping - improved. (Kevin Joseph)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 13 Oct 2004 22:29:09 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: [newbie] shtml question
Message-Id: <5aj042-rj5.ln1@osiris.mauzo.dyndns.org>


Quoth Larry <dontmesswithme@got.it>:
> In article <2t507nF1rat4uU1@uni-berlin.de>,
>  Gregory Toomey <nospam@bigpond.com> wrote:
> > 
> > Mixing server side includes & cgi can be fraught with danger. Try html
> > templates instead. 
> > http://search.cpan.org/~samtregar/HTML-Template-2.7/Template.pm
> > 
> > You might be able to pass a variable by ...page.cgi?k=1000 but I dont have a
> > clue how this interacts with ssi.
> 
> Well, I know what you're talking about.
> 
> But I badly need to sort this problem out!!!
> 
> so forget about TEMPLATE...i need to pass a query string to my cgi script
> ...

Idiot.

*plonk*

-- 
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks]         ben@morrow.me.uk


------------------------------

Date: Wed, 13 Oct 2004 23:53:39 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: [newbie] shtml question
Message-Id: <2t5mliF1qmf05U1@uni-berlin.de>

Ben Morrow wrote:
> Quoth Larry wrote:
>> Gregory Toomey wrote:
>>> Mixing server side includes & cgi can be fraught with danger.
>>> Try html templates instead.
>>> http://search.cpan.org/~samtregar/HTML-Template-2.7/Template.pm
>>> 
>>> You might be able to pass a variable by ...page.cgi?k=1000 but
>>> I dont have a clue how this interacts with ssi.
>> 
>> Well, I know what you're talking about.
>> 
>> But I badly need to sort this problem out!!!
>> 
>> so forget about TEMPLATE...i need to pass a query string to my
>> cgi script ...
> 
> Idiot.

Would you mind explaining how rejecting that idea makes the OP an
idiot?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: 11 Oct 2004 13:34:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Acceptible idiom ?
Message-Id: <cke24u$rsg$1@mamenchi.zrz.TU-Berlin.DE>

Paul Lalli <mritty@gmail.com> wrote in comp.lang.perl.misc:
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:ckdudi$of3$2@mamenchi.zrz.TU-Berlin.DE...
> 
> > But anyway, your logic escapes me.  Even if it were true that
> > '$a != 0 implies $a ne ""' (which it isn't),
> 
> It isn't?  Can you give me a non-zero value which is string-equal to the
> empty string?

    use Scalar::Util qw( dualvar);
    my $paradox = dualvar( 123, '');
    print $paradox + 0, " is also '$paradox'\n"

But I'll admit that I wasn't thinking of this possibility, I was just
confused.  For "normal" Perl variables your implication is true.  That
includes "natural duals" like booleans and (on my system) also $!.

It is another consideration that you must switch off warnings to
make undisturbed use of the implication.

Anno


------------------------------

Date: Wed, 13 Oct 2004 17:28:37 -0400
From: "Martijn Stam" <spam.me@offizi.nl>
Subject: amavisd-new perl patterns
Message-Id: <416d9e06$0$32072$e4fe514c@dreader18.news.xs4all.nl>

@spam_quarantine_to_maps = (
  new_RE( [qr'^(.*)@amstec\.net$'i => 'spam@amstec.net'],
        [qr'^(.*)@ermeds\.com$'i => 'spam@ermeds.com'],
        [qr'^(.*)@flgolfnews\.com$'i => 'spam@flgolfnews.com'],
        [qr'^(.*)@libertyautoclinic\.com$'i => 
'spam@libertyautoclinic.com'],
        [qr'^(.*)@plasticisland\.com$'i => 'spam@plasticisland.com'],
        [qr'^(.*)@sosmeds\.com$'i => 'spam@sosmeds.com'] ),
  $spam_quarantine_to
);

I want Amavis to send the original spam e-mails per domain to 
spam@domain.ext, but with the above patterns only a part of the mails are 
sent to spam@. So everything@domain.ext has to go to spam@domain.ext

And if this works, I would like to have a MySQL lookup for these vars. 
Amavisd-new and Postfix already run on MySQL

Thanks!

Martijn Stam 




------------------------------

Date: Wed, 13 Oct 2004 20:13:21 +0100
From: "Rapier" <a@a.com>
Subject: Re: Concatenating an array into one string?
Message-Id: <1097694815.4694.0@iris.uk.clara.net>

Thanks for all the help.

I am new to perl and still learning.

Thanks again.

"Jürgen Exner" <jurgenex@hotmail.com> wrote in message 
news:BPbbd.89$dI6.22@trnddc03...
> Jürgen Exner wrote:
>
> Aaarrrggg
>
>> Just replace the whole mess with a simple
>>
>>    $jobcat = join '', chomp @test;
>
> Of course this needs to be
>
> chomp @test;
> $jobcat = join '', @test;
>
> Thou shalt not 'improve' code after pasting it into your news reader.
>
> jue
> 




------------------------------

Date: 13 Oct 2004 19:21:06 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Concatenating an array into one string?
Message-Id: <Xns95819C2A9B992asu1cornelledu@132.236.56.8>

"Rapier" <a@a.com> wrote in news:1097694815.4694.0@iris.uk.clara.net:

> Thanks for all the help.
> 
> I am new to perl and still learning.
> 
> Thanks again.

[ full quotation snipped ]

Well, then, you should read the posting guidelines for this group. They are 
posted here frequently.

One of the prime sins to avoid is top-posting and fully quoting someone 
else's post without actually referring to any part of it.

Have fun learning.

Sinan.


------------------------------

Date: Wed, 13 Oct 2004 21:53:06 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Concatenating an array into one string?
Message-Id: <6thbd.73$yk5.40@trnddc01>

Paul Lalli wrote:
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> news:KLbbd.87$dI6.50@trnddc03...
>> Just replace the whole mess with a simple
>>
>>     $jobcat = join '', chomp @test;
>
> This, of course, contains exactly the same error that the original
> did. chomp does not return the modified strings.

Yep, just like I pointed out in my own follow-up posting.

jue 




------------------------------

Date: Wed, 13 Oct 2004 21:27:11 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Creating a random uniqie directory
Message-Id: <vlf042-n05.ln1@osiris.mauzo.dyndns.org>


Quoth "Jürgen Exner" <jurgenex@hotmail.com>:
> chris-usenet@roaima.co.uk wrote:
> > "Jürgen Exner" <jurgenex@hotmail.com> wrote:
> >> Please see "perldoc -q temp":
> >
> > I'd argue that the determination of $temp_dir in that section's
> > example is wrong. Normal *IX approaches imply that $TMPDIR should
> > override the use of /tmp, whereas the example only considers $TMPDIR
> > if /tmp doesn't exist.
> 
> Good catch! I agree, the way $temp_dir is determined
>            my $temp_dir = -d '/tmp' ? '/tmp' : $ENV{TMP} || $ENV{TEMP};
> does not behave as most people would expect.

 ...which is yet another reason to use File::Temp :).

Ben

-- 
        I must not fear. Fear is the mind-killer. I will face my fear and
        I will let it pass through me. When the fear is gone there will be 
        nothing. Only I will remain.
ben@morrow.me.uk                                          Frank Herbert, 'Dune'


------------------------------

Date: 13 Oct 2004 13:02:52 -0700
From: ioneabu@yahoo.com (wana)
Subject: function overloading in Perl
Message-Id: <bf0b47ca.0410131202.2cef8a4@posting.google.com>

I read something about function/method overloading in Perl relating to
OOP, but I was wondering about how to do it normally.

here's the code:

sub SaveToFile
#takes array reference and file name as argument
#and saves array contents to file
{
        my ($array, $filename) = @_;
        open my $file, '>', $filename or die "Couldn't open $filename:
$!";
        print $file @{$array};
        close $file or die "Error closing $filename: $!";
}
sub StringToFile
#like SaveToFile but takes string instead of array reference
{
        my ($string, $filename) = @_;
        open my $file, '>', $filename or die "Couldn't open $filename:
$!";
        print $file $string;
        close $file or die "Error closing $filename: $!";
}

As you can see, I have two functions that basically do the same thing.

In C++ I would give them the same name and the parameter list would
differentiate the two (function overloading).  In Perl, there is no
parameter list as far as I have learned.

What would be the best way to incorporate these functions into one
function if overloading is not possible?

I mean so it can be called as SaveToFile(\@myarray,$filename) or
SaveToFile('my string',$filename) with the appropriate results.

Thanks!

wana


------------------------------

Date: 13 Oct 2004 20:06:48 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: function overloading in Perl
Message-Id: <Xns958199BCE9D0Fcastleamber@130.133.1.4>

wana wrote:

> I mean so it can be called as SaveToFile(\@myarray,$filename) or
> SaveToFile('my string',$filename) with the appropriate results.

check if your first argument is a ref or not.

-- 
John                               MexIT: http://johnbokma.com/mexit/
                           personal page:       http://johnbokma.com/
        Experienced programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html


------------------------------

Date: Wed, 13 Oct 2004 21:39:53 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: hard references/arrays
Message-Id: <pdg042-n05.ln1@osiris.mauzo.dyndns.org>


Quoth "Paul Lalli" <mritty@gmail.com>:
> HOWEVER, in this case all you're doing is printing each element of each
> array, followed by a newline.  Why even bother looping?
> 
> {
>    local $, = "\n";
>    print @array1, @array2, @array3;
> }
> print "\n";

Come now :)

{
    local ($,, $\) = ("\n", "\n");
    print @array1, @array2, @array3;
}

Ben

-- 
   If you put all the prophets,   |   You'd have so much more reason
   Mystics and saints             |   Than ever was born
   In one room together,          |   Out of all of the conflicts of time.
ben@morrow.me.uk                                    The Levellers, 'Believers'


------------------------------

Date: 13 Oct 2004 12:55:37 -0700
From: markus.cl@gmx.de (Markus Dehmann)
Subject: How to package my perl scripts (that depend on other utils)
Message-Id: <c1e48b51.0410131155.59ab14a7@posting.google.com>

Hi,

I have written a piece of software. It's some perl scripts and modules
which depend on jconv, latex and some special latex packages.

What is the best way to distribute such a thing? Just include jconv
and the latex packages? Is there a suitable installation routine, or
do I have write own installation scripts? Could I possibly use the
perl packager (not sure what it is exactly).

It should be as easy as possible for users to install on their
machine.

Thanks for every hint!
Markus


------------------------------

Date: Wed, 13 Oct 2004 18:49:01 GMT
From: Geoff Cox <geoff.cox@removethisplease.freeuk.com>
Subject: HTML::Parser and <p> behaviour?
Message-Id: <irtqm0lj618tedv6hsr8od6db5821b2h6b@4ax.com>

Hello,

I cannot seem to work out how HTML::Parser deals with <p> text </p>
from an html file ... 

It breaks up a paragraph by placing a </p> <p> inside a paragraph of
text in what seems to me to be a random fashion...

any rule at work here?

Cheers

Geoff


------------------------------

Date: 13 Oct 2004 19:19:27 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: HTML::Parser and <p> behaviour?
Message-Id: <Xns95819BE2BEB18asu1cornelledu@132.236.56.8>

Geoff Cox <geoff.cox@removethisplease.freeuk.com> wrote in 
news:irtqm0lj618tedv6hsr8od6db5821b2h6b@4ax.com:

> I cannot seem to work out how HTML::Parser deals with <p> text </p>
> from an html file ... 
> 

Please read the posting guidelines posted here regularly. 

You have asked a stupid question. A stupid question is one that cannot 
generate a useful answer. It is in your best interest to ask smart 
question, i.e. ones that contain enough information so that someone can 
actually help you.

Of course, this is inapplicable if you are just posting for the heck of it 
and are not interested in actually getting your question answered.

So, go back and post a small, self-contained script that still exhibits the 
problem.

> It breaks up a paragraph by placing a </p> <p> inside a paragraph of
> text in what seems to me to be a random fashion...
> 
> any rule at work here?

In the immortal words of MJD, 

If you have `some weird error', the problem is probably with your 
frobnitzer.

(David, thanks for the link :)

Sinan.


------------------------------

Date: Wed, 13 Oct 2004 19:46:26 GMT
From: Geoff Cox <geoff.cox@removethisplease.freeuk.com>
Subject: Re: HTML::Parser and <p> behaviour?
Message-Id: <a31rm05784u5g7stoojk2rogj49dfn35t1@4ax.com>

On 13 Oct 2004 19:19:27 GMT, "A. Sinan Unur"
<1usa@llenroc.ude.invalid> wrote:

>So, go back and post a small, self-contained script that still exhibits the 
>problem.

OK - does the code below help? In fact there are 2 questions here. 

1.  if I have a paragraph of text between <p> and </p> I find that the
text is broken into two parts producing

<p> jajlsdkjklasjdkljakdj </p><p> hakljd laksdj  </p>

2. I am trying to parse 

<ul>
<li>
<li>
</ul>

The code below produces text with <li> jkjkj </li> but I cannot see
how to put the <li>'s between <ul> amd </ul> 

Cheers

Geoff

package MyParser;
use base qw(HTML::Parser);
use strict;
use diagnostics;

my ($in_heading,$in_p,$in_li, $fh);

sub register_fh {
$fh = $_[1];
}
sub reset { ($in_heading,$in_p, $in_li)=(0,0)}

sub start {

    my ( $self, $tagname, $attr, undef, $origtext ) = @_;

    if ( $tagname eq 'h2' ) {
        $in_heading = 1;
        return;
    }

    if ( $tagname eq 'p' ) {
        $in_p = 1;
        return;
    }

    if ( $tagname eq 'li' ) {
        $in_li = 1;
        return;
    }


    if ( $tagname eq 'option' ) {

#    print ("\$origtext has value $origtext \n");

        main::choice( $attr->{ value } );

    }

}

sub end {
    my ( $self, $tagname, $origtext ) = @_;
    if ( $tagname eq 'h2' ) {
        $in_heading = 0;
        return;
    }

    if ( $tagname eq 'p' ) {
        $in_p = 0;
        return;
    }

    if ( $tagname eq 'ul' ) {
        $in_li = 0;
        return;
    }


}

sub text {
    my ( $self, $origtext ) = @_;
    print $fh "<h2>$origtext</h2> \n" if $in_heading;
    print $fh "<p>$origtext</p> \n" if $in_p;
    print $fh "<li>$origtext</li> \n" if $in_li;


}

package main;

use File::Find;













>
>> It breaks up a paragraph by placing a </p> <p> inside a paragraph of
>> text in what seems to me to be a random fashion...
>> 
>> any rule at work here?
>
>In the immortal words of MJD, 
>
>If you have `some weird error', the problem is probably with your 
>frobnitzer.
>
>(David, thanks for the link :)
>
>Sinan.



------------------------------

Date: Wed, 13 Oct 2004 12:52:21 -0700
From: "187" <bigal187@remove.rx.eastcoasttfc.com>
Subject: Re: HTML::Parser and <p> behaviour?
Message-Id: <2t5faeF1rmtlcU1@uni-berlin.de>

A. Sinan Unur wrote:
> Geoff Cox <geoff.cox@removethisplease.freeuk.com> wrote in
> news:irtqm0lj618tedv6hsr8od6db5821b2h6b@4ax.com:
>
>> I cannot seem to work out how HTML::Parser deals with <p> text </p>
>> from an html file ...
>>
>
> Please read the posting guidelines posted here regularly.
>
> You have asked a stupid question. A stupid question is one that cannot
> generate a useful answer. It is in your best interest to ask smart
> question, i.e. ones that contain enough information so that someone
> can actually help you.
>
> Of course, this is inapplicable if you are just posting for the heck
> of it and are not interested in actually getting your question
> answered.
>
> So, go back and post a small, self-contained script that still
> exhibits the problem.

Grated soem sample code would of been nice, the situation was still
described to the point wher someone who has worked with that module
might be able to help.

Your assine tone, as well as your direct insults to the OP, was
completely unwarrented.

You could of just rplied asking for more information, but if you could
not tell the situation from the initial post then I doubt you would of
been able to help. (I would attemt but I am not very familiar with this
module).

There is NO excuse for your tone in this thread.




------------------------------

Date: 13 Oct 2004 20:16:39 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: HTML::Parser and <p> behaviour?
Message-Id: <Xns9581A595263BCasu1cornelledu@132.236.56.8>

Geoff Cox <geoff.cox@removethisplease.freeuk.com> wrote in
news:a31rm05784u5g7stoojk2rogj49dfn35t1@4ax.com: 

> On 13 Oct 2004 19:19:27 GMT, "A. Sinan Unur"
> <1usa@llenroc.ude.invalid> wrote:
> 
>>So, go back and post a small, self-contained script that still
>>exhibits the problem.
> 
> OK - does the code below help? In fact there are 2 questions here. 

No. 

It is not self-contained. That is, I cannot, without doing extra work, just 
run it and see what happens.

Sinan.

-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



------------------------------

Date: 13 Oct 2004 20:24:19 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: HTML::Parser and <p> behaviour?
Message-Id: <Xns9581A6E21B230asu1cornelledu@132.236.56.8>

Geoff Cox <geoff.cox@removethisplease.freeuk.com> wrote in
news:a31rm05784u5g7stoojk2rogj49dfn35t1@4ax.com: 

> OK - does the code below help? In fact there are 2 questions here. 
> 
> 1.  if I have a paragraph of text between <p> and </p> I find that the
> text is broken into two parts producing

Here is the relevant part from your code:

> sub text {
>     my ( $self, $origtext ) = @_;
>     print $fh "<h2>$origtext</h2> \n" if $in_heading;
>     print $fh "<p>$origtext</p> \n" if $in_p;
>     print $fh "<li>$origtext</li> \n" if $in_li;
> 
> 
> }

I suspect the handler is being called multiple times, each time with a 
different part of the original text. You can test this hypothesis by 
putting a debug statement in here.

-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



------------------------------

Date: Wed, 13 Oct 2004 21:13:53 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Lagrange Interpolating Polynomial
Message-Id: <1te042-n05.ln1@osiris.mauzo.dyndns.org>


Quoth Brian Troutwine <goofy_headed_punk@msn.com>:
> On Tue, 12 Oct 2004 12:48:52 +0100, Ben Morrow wrote:
> 
> > You could try changing to ::GMP or something to see if it makes
> > a difference.
> 
> Unfortunately, I need rational number support, and since Math::Fraction
> doesn't work particularly well, BigRat seems my best option. Do you know
> of any better? (I looked into ::GMP, but that seemed to be large numbers
> and not large rationals numbers.)

I know only what it says in the Math::BigRat (0.10) perldoc, which
implies that Math::BigRat uses Math::BigInt ('s internals) to do all its
calculations, and that

use Math::BigRat lib => 'GMP';

will use Math::BigInt::GMP to do your BigRat stuff (if it's installed).

Ben

-- 
"If a book is worth reading when you are six,                * ben@morrow.me.uk
it is worth reading when you are sixty." - C.S.Lewis


------------------------------

Date: Wed, 13 Oct 2004 21:22:55 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: localizing %SIG handlers
Message-Id: <vdf042-n05.ln1@osiris.mauzo.dyndns.org>


Quoth anno4000@lublin.zrz.tu-berlin.de (Anno Siegel):
> Ben Morrow  <usenet@morrow.me.uk> wrote in comp.lang.perl.misc:
> > 
> > There are two possible ways out, AFAICT. The first is that assigning
> > undef to a member of %SIG currently has undefined effects. In fact, what
> > happens is that any assigned value that 1. isn't a glob or a reference
> > and 2.  stringifies to the empty string causes the signal handler to be
> > set to SIG_DFL. At the potential risk of breaking programs that rely on
> > the (undocumented) consequence that $SIG{FOO} = undef; is equivalent to
> > $SIG{FOO} = 'DEFAULT'; it would be relatively trivial to change
> > mg.c:Perl_magic_setsig to cause undef to leave the signal handler
> > unchanged, instead of setting it to the default.
> 
> Ah, but that would mean that a pristine $SIG{FOO} wouldn't be restored
> after { local $SIG{ FOO} = \&something }.  \&something would stick,
> which is certainly unexpected.

OK, so initialise all of %SIG to 'DEFAULT' rather than to undef
(especially as that's what it's implicitly initialised to anyway). Then
when Perl restores the 'DEFAULT' at the end of the block it will restore
SIG_DFL.

> I also admit that I had naively assumed the, as you point out,
> undocumented behavior that undef'ing a sig handler resets it to
> the default.

Yes... it is a natural assumption, especially given that %SIG starts
empty.

> > The alternative, which would be rather harder to implement but would
> > only break programs which assume local $SIG{FOO}; sets SIGFOO to SIG_DFL
> > rather than $SIG{FOO} = undef;, is to special-case %SIG in
> > scope.c:S_save_scalar_at to keep the old value of $SIG{FOO} on
> > localising rather than assigning undef.
> 
> ...so basically, local() would have to be made aware that it is
> localizing a sig handler, instead of dealing with it in %SIG magic.

Yup.

<objects which restore handler in DESTROY>
> POSIX::SigAction objects appear to implement that, though I don't see
> a DESTROY method.  Maybe not...

No... I wondered about POSIX::SigAction, but those objects are *just* a
Perl version of struct sigaction. Creating an object doesn't install a
signal handler at all; you have to call POSIX::sigaction to do that. 

> In the particular case, the solution was to scratch local().  It
> was only there out of orderliness in the first place :)

Yes. However, it *ought* to work: the reason local is useful is because
it's so hard to catch all the exits from a dynamic scope.

Ben

-- 
  Joy and Woe are woven fine,
  A Clothing for the Soul divine       William Blake
  Under every grief and pine          'Auguries of Innocence'
  Runs a joy with silken twine.                                ben@morrow.me.uk


------------------------------

Date: 13 Oct 2004 19:24:39 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl to monitor server stats
Message-Id: <Xns95819CC47D80Aasu1cornelledu@132.236.56.8>

[ top-posting fixed ... don't do that ]

"KWall" <mirak63@carolina.rr.com> wrote in
news:bYudnSMsdvsU2_DcRVn-ug@giganews.com: 

> "Tad McClellan" <tadmc@augustmail.com> wrote in message 
> news:slrncmqgci.3eb.tadmc@magna.augustmail.com...

>> What kind of server?
>>
>> HTTP? SMTP? FTP? ...
>>
>>
>> If a "web server" then what kind of web server?
>>
>> IIS?  Apache? ...

> I'd like to be able to pull Windows server stats like those in Task
> Manager and push them into a database for reporting. CPU utilization,
> RAM in use, stuff like that. I can already pull hard disk stats but
> haven't seen any modules that Windows server stats.

You should always, always consult http://search.cpan.org/ first.

I have not used them, but have you looked at

Win32::NetAdmin

and

Win32::NetResource

If you did, what are their shortcomings? If not, why not?

Sinan.


------------------------------

Date: Wed, 13 Oct 2004 22:31:53 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Perl to monitor server stats
Message-Id: <9fj042-rj5.ln1@osiris.mauzo.dyndns.org>

[quotng fixed: DON'T top-post]

Quoth "KWall" <mirak63@carolina.rr.com>:
> "Tad McClellan" <tadmc@augustmail.com> wrote in message 
> news:slrncmqgci.3eb.tadmc@magna.augustmail.com...
> > KWall <mirak63@carolina.rr.com> wrote:
> >
> >> to monitor Windows server statistics?
> >
> > What kind of server?
> >
> > HTTP? SMTP? FTP? ...
>
> I'd like to be able to pull Windows server stats like those in Task Manager 
> and push them into a database for reporting. CPU utilization, RAM in use, 
> stuff like that. I can already pull hard disk stats but haven't seen any 
> modules that Windows server stats.

I think you want the WMI modules (search http://search.cpan.org), but
I'm afraid I can offer you no help in using them.

Ben

-- 
  The cosmos, at best, is like a rubbish heap scattered at random.
                                                         - Heraclitus
  ben@morrow.me.uk


------------------------------

Date: Wed, 13 Oct 2004 20:52:03 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Perls system() call fails in a cgi-file running on win2k and apache
Message-Id: <3kd042-n05.ln1@osiris.mauzo.dyndns.org>


Quoth mister_x_sun@hotmail.com (Mr. Zeus):
> Here the code:

You seem not to be using strictures; are you using warnings?

Every (yes, *every*) program you write, certainly every program you
post here, should start with

use strict;
use warnings;

> $TtH         = "\"c:/programme/apache
> group/apache2/cgi-bin/tth.exe\"";

You would be better off using single quotes here:

my $TtH = '"c:/programme/.../tth.exe"';

> $mode = "";

I take it you provide a different value for $mode in the real program?

> @args = ($TtH, "-L -t -r -w0 $mode", "<tth_in.dat", ">tth_out.dat",
> "2>tth_err.dat");
> system(@args)== 0
>   or die "system @args failed: $?";
>
> Here the result:
> 
> system "c:/programme/apache group/apache2/cgi-bin/tth.exe" -L -t -r
> -w0  <tth_in.dat >tth_out.dat 2>tth_err.dat failed: 256 at
> C:\Programme\Apache Group\Apache2\cgi-bin\wikitth.pl line 3252.

The code is essential to finding this problem: the problem is with how
you have called system.

system LIST does not use the command shell, it invokes the program
directly. Three consequences of this are

1. Stdio redirections (<, >, >>, | &c.) will not work: they are
performed by the shell.

2. Every argument must be provided as a separate item in the list. qw//
is often useful for this, I find, as is the idiom

my @args = (
    -L => 
    -r => 
    -w => 0,
    $mode
);

3. Arguments and commands with spaces in them do not need quoting. Perl
will provide the arguments given directly to execvp(2); under Unix and
other OSen with C-compatible argument passing conventions, this will
pass them straight into the program with no interpolation at all; under
Win32 the C RTL will (theoretically) deal with quoting each argument
such that the receiving program parses the command line correctly.

So, your system command was equivalent to typing

"\"c:/.../tth.exe\"" "-L -t -r -w0 " "<tth_in.dat" ">tth_out.dat" ...

into cmd.exe. Unsurprisingly, this didn't work. You have two options:

1. If you are using perl 5.8, you could try pretending you're on Unix
and doing a fork/exec pair, redirecting STD{IN,OUT,ERR} after the fork
and passing exec a list of (unquoted) arguments. This may, if you're
lucky, work... it will also be portable to Unixen, if you care about
that. This *should* keep the benefits of system/exec LIST, namely that
you don't need to worry about shell metachars in your arguments.

2. Use system STRING instead; in this case you want to keep $Tth as it
is but call system like

system "$Tth -L -t -r -w0 $mode <tth_in.dat >tth_out.dat ...";

i.e. with one string correctly quoted as you would type it into cmd.exe.
This string will be passed to cmd /c, which will then do the
redirections for you and will also require the quotes around the exe
name. This has the potential problem that if (say) $mode contains any
shell metachars (and what cmd.exe's metechars are is rather hard to say;
certainly "\%><|, possibly ^, perhaps others; the only thing you really
know is safe is /\w/) you will have to deal with quoting them in a way
cmd.exe finds acceptable yourself. You may also find you need to use
back- instead of forward-slashes for paths: cmd.exe is about the only
part of windows that cares which you use (which is why it's best to use
/ in general, as perl prefers it), but I really don't know if it works
to invoke an exe with a forward-slashed path.

Ben

-- 
                Outside of a dog, a book is a man's best friend.
                Inside of a dog, it's too dark to read.
ben@morrow.me.uk                                                  Groucho Marx


------------------------------

Date: Wed, 13 Oct 2004 22:28:01 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Restricting a program to one running instance
Message-Id: <18j042-rj5.ln1@osiris.mauzo.dyndns.org>


Quoth Michele Dondi <bik.mido@tiscalinet.it>:
> I apologize if the subject is not really appopriate to this post, but
> I really couldn't think of a better one...

How's that? :)

> To come to the point, I have a process that (partially) daemonizes and
> uses a mechanism to prevent having more than one instance running on
> any given machine.
> 
> As of it is now, I must say that it has been working perfectly for
> quite a while and I've not had any problem with it. Basically the key
> code snippet is as follows:
> 
>   my $lockfile = "$lockdir/$pfx-$host";
>   sysopen my $lock, $lockfile, O_CREAT | O_EXCL 
>     or die "$0 already running on $host\n";
>   my $havelock = 1;
>   # ...
> 
> However (also) for learning purposes, I've been thinking of improving
> it to cope with the unlikely possibility that a badly crashed machine
> prevented my signal handlers or C<END> block to take care of lockfile
> removal.

What I have done in the past in this situation is

sysopen my $LOCK, $lockfile, WR_ONLY | O_CREAT, 0600
    or die "can't open lockfile: $!";
flock $LOCK, LOCK_EX | LOCK_NB
    or die "I'm already running!";

If you wanted to be really careful you could check that $! ==
EWOULDBLOCK before concluding you were already running.

The advantage of this, obviously, is that the kernel will take care of
releasing the lock however the process terminates (and if the whole
machine goes down the lock's *certainly* gone :) ).

> So the additional steps that I'm taking into account are:
> 
> (i) writing the pid of the running instance into the lockfile and
> check for its existence,
> (ii) once (i) is done, then also check that the process corresponding
> to the stored pid corresponds to a program called like $0.
> 
> Now, the questions are: would (i) be a good idea?

Yes. It would be anyway, so you can find it and kill it easily if it
gets jammed.

> Would (ii) be a good idea too?

Not really. The risk that either it will be a process that matches that
shouldn't (not *that* likely, but rather more so if someone's being
malicious) or a process that doesn't match that should (consider
starting the program as 'prog', '~/bin/prog', 'perl ../bin/prog'; I have
no idea what the kernel puts in argv (although I would hope the first
two were ('/usr/bin/perl', '/dev/fd/3') or in /proc/$$/cmdline for each
of these cases, and I suspect there is no well-defined answer).

If you make the pidfile secure, then you can simply check if that pid is
still running (kill 0 => $pid); if you're worried about pid wraparound
then you really need to get some positive check that the process
concerned is one of yours, such as (in the extreme case) connecting to a
Unix-domain socket the other copy is listening on and performing a
secure authentication exchange.

> Also, (and on a Perl-related basis, finally!) if the answers to the
> above questions are positive, then when I open a file with sysopen(),
> can/should I subsequently use the "standard" IO operators (i.e. those
> I'd use with an open()ed file) and functions to read and write to it?

Yes. Perl's sysopen does an open(2) and then a fdopen(3) (or the PerlIO
equivalent), so the FH you get back is exactly equivalent to one from
open.

> As for the point (ii) above, since the program is to be run on Linux
> anyway, it would seem sensible to me to read the relevant info from
> /proc myself (don't know if it could be doable under other UNICES

Plan9? :)

> ): is it recommended to use some module or ad hoc code instead?

I'd probably recommend using a module on principle (the Proc::
hierachy); in practice, I'd probably just grep it out of
/proc/pid/cmdline :)

> Last, since I'm not much confident with this kind of programming,
> could you please be so kind and post some explicit minimal code
> snippet?

Oh, come now, the advantage of /proc is that it's just like ordinary
files; and I'm quite sure you can write a program to read a pid from a
file, open another file based on that, and check if it matches
/^\Q$^X\E\s+\Q$0\E(?:\s|$)/ :).

If you want to use a module, then I know no more than that they exist,
I'm afraid...

Ben

-- 
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
   From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
 /Alcestis/)        [ flame, and falls out of sight. ]         ben@morrow.me.uk


------------------------------

Date: Wed, 13 Oct 2004 21:05:14 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: undef takes forever
Message-Id: <qce042-n05.ln1@osiris.mauzo.dyndns.org>


Quoth anno4000@lublin.zrz.tu-berlin.de (Anno Siegel):
> Bart Lateur  <bart.lateur@pandora.be> wrote in comp.lang.perl.misc:
> > KKramsch wrote:
> > 
> > >so the current version of the script tests for the soundness of
> > >the stored file by saving the hash to a dummy file first, then
> > >retrieving the hash from memory into a temporary variable $temp,
> > >and making sure that $temp is defined and that %$temp has the right
> > >number of keys.  If all this is as it should be, then the dummy
> > >file is used to overwrite the old version of the hash stored on
> > >disk.
> > >
> > >  It turns out, however, that this version of the script is about
> > >10x slower than the original version,
> > 
> > I think the extra slowness is due to your memory being full,causing
> > extensive swapping.
> > 
> > I'd try to move the check to an external script, which needn't be so
> > careful about carefully releasing all memory. If necessary, you can
> > shortcircuit the garbage collection for that external script using a
> > carefully chosen exec().
> 
> How so?  Did you mean exit()?

A common trick for programs which leak, at least on Unix, is to re-exec
yourself every so often (having arranged things so you can get back into
the state you were in, of course), which will 'deal' with the leaks.

I'm not sure if this applies here though: will perl go through a full GC
run if you exec, even though it doesn't need to free the memory? I guess
it may, in order to call DESTROY handlers...

Ben

-- 
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
   From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
 /Alcestis/)        [ flame, and falls out of sight. ]         ben@morrow.me.uk


------------------------------

Date: Wed, 13 Oct 2004 21:00:39 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Using a variable size with the repetition quantifier
Message-Id: <74e042-n05.ln1@osiris.mauzo.dyndns.org>


Quoth aymerphilippe@hotmail.com (Philippe Aymer):
> Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote in message news:<Pine.SOL.3.96.1041012152434.11683A-100000@vcmr-86.server.rpi.edu>...
> > On 12 Oct 2004, Philippe Aymer wrote:
> > 
> > >Now, I still have a trouble. Because:
> > >
> > >/X(\d)((??{"\\w{$1}"}))/
> > >
> > >works, but in my string, I also have to match newline. So I did:
> > >
> > >/X(\d)(??{"\\w{$1}"})/s
> > >
> > >which doesn't work (seems to apply only to //, not things within
> > >(?..)), then:
> > 
> > The /s modifier only affects the '.' metacharacter.  \w doesn't match \n.
> 
> oups... I should have written:
> 
> /X(\d)(??{".{$1}"})/s
> 
> that's what I'm using ("xyz" in my example coule be anything, even non
> printable char).

Maybe /s doesn't correctly propagate into (regex)-runtime-interpolated
strings (this is probably a bug in the regex engine, if it's true); try

/X(\d)(??{"(?s).{$1}"})/s

> > >/X(\d)(??{"[\\w\n]{$1}"})/
> > >
> > >which doesn't work neither... (?)
> > 
> > This should work:
> > 
> >   /X(\d)((??{ "[\\w\\n]{$1}" }))/
> 
> ok, I have trouble with my fingers... I'm using ".\\n", but no it's
> not working.

CUT AND PASTE CODE. NEVER RETYPE IT.

> So I try this program:
> 
> my $string = "DA3xyzB4ab\nc";
> 
> print "==>$string<==" . "\n\n";
> 
> if ($string =~ /
> 	D
> 	(
> 		A
> 		(\d)
> 		(?{ print "===>$2<===\n"; })
> 		( (??{ "[\\w\\n]{$2}" }) )

Again you have \w... please say what you mean.

> 		(?{ print "===>$3<===\n"; })
> 	)
> 	(
> 		B
> 		(\d)
> 		(?{ print "===>$5<===\n"; })
> 		( (??{ "[\\w\\n]{$5}" }) )
> 		(?{ print "===>$6<===\n"; })
> 	)
> /xs) {
> 	print "\n";
> 	print "DATA : =>$1<= " . length($1) . "\n";
> 	print "DATA : =>$4<= " . length($4) . "\n";
> }
> 
> The second pattern : "[.\\n]{$5}" doesn't work...

What do you mean, it doesn't work? . is not a metachar inside character
classes, so this matches $5 occurences of "." or "\n". You want

"(?:.|\\n){$5}"

or use (?s) as above.

Ben

-- 
I've seen things you people wouldn't believe: attack ships on fire off
the shoulder of Orion; I watched C-beams glitter in the dark near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die.                                                   ben@morrow.me.uk


------------------------------

Date: 13 Oct 2004 14:23:27 -0700
From: kejoseph@hotmail.com (Kevin Joseph)
Subject: Win2k - Ping - improved.
Message-Id: <54c48ac0.0410131323.59838e80@posting.google.com>

I am trying to write a Perl script which provides more detailed
information than the built in ping command. The built in command only
states <10ms, but I would like more details than that (as in Linux).

I wrote the following code (I have Perl v5.8.4 from ActiveState) which
works fine provided I comment the for loop with the sleep statement.
If I invoke it multiple times from the command line, I get 1-2ms on a
LAN which is ok.

The moment I uncomment the for loop, the first iteration works fine,
subsequent show only 0ms (almost as if its caching it.) Any ideas as
to what I am doing wrong ?

Thanks,
Kevin.

use Net::Ping ;
use Time::HiRes qw(gettimeofday);

#for ($i=0 ; $i < 5 ; $i++ )
#{
$hostname=some_host ;
$p = Net::Ping->new(icmp) ;
$p->hires() ;
($ret, $duration, $ip) = $p->ping($hostname,5) ;

($sec, $usec) = gettimeofday ;
$time = scalar(localtime($sec)) ;
printf("$time $hostname [ip: $ip] is alive : time : %.5f ms)\n",
1000*$duration)
if $ret ;

$p->close() ;
#sleep(1) ;
#}


------------------------------

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 7241
***************************************


home help back first fref pref prev next nref lref last post