[25231] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7476 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 2 14:10:33 2004

Date: Thu, 2 Dec 2004 11:10: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           Thu, 2 Dec 2004     Volume: 10 Number: 7476

Today's topics:
    Re: Perl Executable and Script Name -- NOT Args <usenet@morrow.me.uk>
    Re: Problem parsing tcpdump tcp[13] output <romain.lorenzini@laposte.net>
    Re: Problem parsing tcpdump tcp[13] output <tadmc@augustmail.com>
    Re: Query about Spreadsheet::WriteExcel <willbounce@yoshiwara.org.uk>
    Re: Reaping dead children <usenet@morrow.me.uk>
        Reference to hash and array <corleone@godfather.com>
    Re: Reference to hash and array (Anno Siegel)
    Re: Reference to hash and array <karlUNDERSCOREkramsch@yahooPERIODcom.invalid>
    Re: sorting objects with "sort" and subroutine j.eckles@computer.org
    Re: sorting objects with "sort" and subroutine <tadmc@augustmail.com>
    Re: System command <usenet@morrow.me.uk>
    Re: Unix commands and perl <usenet@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 30 Nov 2004 18:11:18 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Perl Executable and Script Name -- NOT Args
Message-Id: <6npu72-io4.ln1@osiris.mauzo.dyndns.org>


Quoth "Paul Lalli" <mritty@gmail.com>:
> "Walt Stoneburner" <wls@wwco.com> wrote in message
> news:c1fca1a1.0411290802.58a8719f@posting.google.com...
> 
> The currently executing perl script is stored in $0

 ...but it may (under some OSen) be just a name, with no path. The
FindBin module is supposed to solve this problem for you, though I have
found it a little unreliable in the past; I believe some work has been
done on it recently, though.

Ben

-- 
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
                                                               ben@morrow.me.uk


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

Date: Thu, 02 Dec 2004 15:03:27 +0100
From: Romain <romain.lorenzini@laposte.net>
To: tadmc@augustmail.com
Subject: Re: Problem parsing tcpdump tcp[13] output
Message-Id: <41AF20AF.2040204@laposte.net>

Here's my real script but I still have the same problem

#!/usr/bin/perl
$commande = "tcpdump -vvni eth1 tcp[13] == 18";
print "$commande\n";
($pid = open(PIPE,"$commande |")) or die "Error: $!\n";
while (defined($line = <PIPE>))
{
         print $line;
}

When I redirect the tcpdump command in a file and I do a cat file.log | 
 ./test.pl, it works fine.

Thanks in advance pour your help.

Tad McClellan wrote:
> Romain <romain.lorenzini@laposte.net> wrote:
> 
> 
>>Here is the beginning of my script:
>>
>>#!/usr/bin/perl
> 
> 
> 
>    use warnings;
>    use strict;
> 
> Ask for all the help you can get!
> 
> Doubly so when attempting debugging!
> 
> 
> 
>>$command = 'tcpdump -vvni eth0 tcp[13] == 18'
>>($pid = open(PIPE,"$command |")) or die "Error: $!\n";
> 
> 
> 
>    syntax error at ./temp line 4, near "("
> 
> 
> 
>>It doesn't print anything 
> 
> 
> 
> 'course not, it doesn't even compile...
> 
> 
> 
>>although tcpdump catured packets.
> 
> 
> 
> That's a real trick.
> 
> An unbelievable trick actually, how can tcpdump captur packets when
> the program that launches it doesn't even compile?
> 
> 
> 
>>Could anyone help me about that?
> 
> 
> 
> Show us your real code.
> 
> Have you seen the Posting Guidelines that are posted here frequently?
> 
> 


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

Date: Thu, 2 Dec 2004 09:17:43 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Problem parsing tcpdump tcp[13] output
Message-Id: <slrncqucgn.b08.tadmc@magna.augustmail.com>

Romain <romain.lorenzini@laposte.net> wrote:

> Here's my real script but I still have the same problem

[snip]

> Tad McClellan wrote:

[snip]


Please do not top-post.

Please do not send "stealth CCs".

They are seen as being rude. 


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 02 Dec 2004 17:07:40 +0000
From: Carl Inglis <willbounce@yoshiwara.org.uk>
Subject: Re: Query about Spreadsheet::WriteExcel
Message-Id: <63guq09afml518hatubr6rrff6nfui1ptb@4ax.com>

On Fri, 10 Sep 2004 03:01:05 +0000 (UTC), A Ymous
<a.ymous3@btinternet.com> wrote:

>When I close a spreadsheet generated by Spreadsheet::WriteExcel
>containing formulas (using $worksheet->write_formula), Excel always asks
>if I want to save the changes made even if no changes have been made
>while using Excel.
>
>Is this normal behaviour?
>
>(Using v2.03 and ActivePerl 5.8.4 on XP )

(Please excuse late reply; I'm scanning forward through the group to
see if the answer to my current question has been previously posted).

I suspect that you're using Office XP or 2003.

The documentation for Spreadsheet::WriteExcel says: "The Excel file
produced by this module is compatible with Excel 5, 95, 97, 2000, and
2002."

Excel has had to convert one or more parts of the file (probably the
formulas in this instance) to the later version. This has caused it to
mark the file as "changed".

Hope that helps,

Carl
-- 
"Rude alert. Rude alert. An electrical fire has knocked out my voice 
recognition unicycle. Many Wurlitzers are missing from my database. Abandon 
shop. This is not a daffodil. Repeat: This is _not_ a daffodil."
-Holly, 'Red Dwarf'


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

Date: Tue, 30 Nov 2004 17:43:48 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Reaping dead children
Message-Id: <k3ou72-io4.ln1@osiris.mauzo.dyndns.org>


Quoth fake@tu-bs.de:
> I'm having problems reaping my dead children.
> 
> I have written a perl script that starts a monster program that
> determines optimal schedules for my companies power plants.  It can
> happen that the optimisation software takes hours, months, or years.
> Obviously, we would like to interrupt the program when that happens, but
> my perl script is blocked until the monster finishes, or until it's
> interrupted.  So I start a second process with "fork" that writes info
> from the log file that the monster is continually writing.  I don't want
> that second process to become a zombie, so I reap dead children ising:
> 
> use POSIX ":sys_wait_h";
> 
> $SIG{CHLD} = \&REAPER;
> 
> sub REAPER {    # reap my dead children to avoid zombies
>   my $stiff;
>   while (($stiff = waitpid(-1, WNOHANG)) > 0) { }
>   $SIG{CHLD} = \&REAPER;
> }
> 
> Now my child can rest in peace.
> 
> But, and here's the problem, if monster terminates with an error
> message, I want to cath that, and analyse why.  With any kind of
> reaping,  including
> 
> $SIG{CHLD} = 'IGNORE'
> 
> (I am really not interested in why my child dies), the status code
> returned by monster is changed.  I don't care that happens to dead
> children started by "fork", but it is vital to check why a child dies
> that is started with "system".  What can be done?

Create the 'monster' child yourself with fork/exec. Then you don't need
the other child: the main program can deal with reading the logfile and
killing it when necessary.

To answer your actual question, $? is only valid *inside* the
sighandler, and if you have one the return value of system is invalid.
So, find out the pid of your 'monster' child (you will need to do the
system by hand with fork/exec to do this), and store it in a global; in
the sighandler, check if $stiff == $monster and if it is stick $? into
another global that you can look at back in the main program. You *will*
find you get nasty effects if you have a waitpid($monster) in the main
program and a waitpid(-1) in the sighandler running at the same time;
I'd probably use eval { POSIX::pause } in the main program and then die
in the sighandler if we've got the monster child.

Yes, all this business with globals is pretty nasty; but that's signals
for you, I'm afraid... :). You may be able to make the sighandler a
closure: something like

sub run_monster {
    my $monster_pid = ...;
    my $monster_status;

    $SIG{CHLD} = sub {
        ...;
        if ($stiff == $monster_pid) {
            $monster_status = $?;
            die;
        }
    };
}

but I haven't tested that.

Ben

-- 
               We do not stop playing because we grow old; 
                  we grow old because we stop playing.
                            ben@morrow.me.uk


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

Date: Thu, 2 Dec 2004 22:37:11 +0900
From: Vito Corleone <corleone@godfather.com>
Subject: Reference to hash and array
Message-Id: <20041202223711.70c830f3.corleone@godfather.com>

Hi,
I downloaded a module that need me to input the value in very confusing
way. For example:
$m = Module::->new( 
  { 'servers' => [ "192.168.1.0:5500", "192.168.1.1:5500" ],
    'debug'   => 0 } );

You put the list of your servers IP and port number into servers. I put
my servers list in config file. It looks like this:
use constant SERVERS => '192.168.1.0:5500 192.168.1.1:5500';

And then when I load the module, I do:
my @servers = split(" ", SERVERS);
$m = Module::->new(
  { 'servers' => \@servers,
    'debug'   => 0 } );

So far so good. But you can also load the module this way.
$m = Module::->new( 
  { 'servers' => [ "192.168.1.0:5500", ["192.168.1.1:5500", 3] ],
    'debug'   => 0 } );

Besides IP and port number, it also takes the value of the server (ie:
3). I want to make my config file looks like:
use constant SERVERS => '192.168.1.0:5500 192.168.1.1:5500,3';

But I don't know how can I pass these values to the module. Or is there
any better way to keep these values in config file? Please help, and
thanks in advance.

--vc



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

Date: 2 Dec 2004 13:49:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Reference to hash and array
Message-Id: <con6gq$g78$1@mamenchi.zrz.TU-Berlin.DE>

Vito Corleone  <corleone@godfather.com> wrote in comp.lang.perl.misc:
> Hi,
> I downloaded a module that need me to input the value in very confusing
> way. For example:
> $m = Module::->new( 
>   { 'servers' => [ "192.168.1.0:5500", "192.168.1.1:5500" ],
>     'debug'   => 0 } );
> 
> You put the list of your servers IP and port number into servers. I put
> my servers list in config file. It looks like this:
> use constant SERVERS => '192.168.1.0:5500 192.168.1.1:5500';
> 
> And then when I load the module, I do:
> my @servers = split(" ", SERVERS);
> $m = Module::->new(
>   { 'servers' => \@servers,
>     'debug'   => 0 } );
> 
> So far so good. But you can also load the module this way.
> $m = Module::->new( 
>   { 'servers' => [ "192.168.1.0:5500", ["192.168.1.1:5500", 3] ],
>     'debug'   => 0 } );
> 
> Besides IP and port number, it also takes the value of the server (ie:
> 3). I want to make my config file looks like:
> use constant SERVERS => '192.168.1.0:5500 192.168.1.1:5500,3';
> 
> But I don't know how can I pass these values to the module. Or is there
> any better way to keep these values in config file? Please help, and
> thanks in advance.

Untested:

    my @servers = map /,/ ? [ split /,/] : $_, split ' ', SERVERS;

Anno


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

Date: Thu, 2 Dec 2004 16:44:11 +0000 (UTC)
From: KKramsch <karlUNDERSCOREkramsch@yahooPERIODcom.invalid>
Subject: Re: Reference to hash and array
Message-Id: <congor$f2g$1@reader1.panix.com>

In <20041202223711.70c830f3.corleone@godfather.com> Vito Corleone <corleone@godfather.com> writes:

>Hi,
>I downloaded a module that need me to input the value in very confusing
>way. For example:
>$m = Module::->new( 
>  { 'servers' => [ "192.168.1.0:5500", "192.168.1.1:5500" ],
>    'debug'   => 0 } );

>You put the list of your servers IP and port number into servers. I put
>my servers list in config file. It looks like this:
>use constant SERVERS => '192.168.1.0:5500 192.168.1.1:5500';

>And then when I load the module, I do:
>my @servers = split(" ", SERVERS);
>$m = Module::->new(
>  { 'servers' => \@servers,
>    'debug'   => 0 } );

>So far so good. But you can also load the module this way.
>$m = Module::->new( 
>  { 'servers' => [ "192.168.1.0:5500", ["192.168.1.1:5500", 3] ],
>    'debug'   => 0 } );

>Besides IP and port number, it also takes the value of the server (ie:
>3). I want to make my config file looks like:
>use constant SERVERS => '192.168.1.0:5500 192.168.1.1:5500,3';

>But I don't know how can I pass these values to the module. Or is there
>any better way to keep these values in config file? Please help, and
>thanks in advance.

What Anno posted is right, I'm sure, but the code below may be
easier to follow.

# untested
my @servers;
for my $info (split ' ', SERVERS) {
  # $info is either of the form ip:port" or "ip:port,num"
  my ($ip_port, $num) = split /,/, $info;
  if ($num) {
    # $info is of the form "ip:port,num"
    push @servers, [$ip_port, $num];
  }
  else {
    # info is of the form "ip:port"
    push @servers, $info;
  }
}

my $m = Module::->new( { 'servers' => \@servers, 
                         'debug'   => 0 } );

__END__

Makes sense?

	Karl

-- 
Sent from a spam-bucket account; I check it once in a blue moon.  If
you still want to e-mail me, cut out the extension from my address,
and make the obvious substitutions on what's left.


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

Date: 2 Dec 2004 07:03:16 -0800
From: j.eckles@computer.org
Subject: Re: sorting objects with "sort" and subroutine
Message-Id: <1101997196.906456.199470@c13g2000cwb.googlegroups.com>

test...



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

Date: Thu, 2 Dec 2004 10:09:47 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: sorting objects with "sort" and subroutine
Message-Id: <slrncqufib.b3g.tadmc@magna.augustmail.com>

j.eckles@computer.org <j.eckles@computer.org> wrote:

> test...


*plonk*


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 30 Nov 2004 18:24:58 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: System command
Message-Id: <qgqu72-io4.ln1@osiris.mauzo.dyndns.org>


Quoth Tony Curtis <tony_curtis32@yahoo.com>:
> >> On 30 Nov 2004 03:18:49 -0800,
> >> "Varun Jindal" <varunjindal@yahoo.com> said:
> 
> > I got it.  Thanks for your help and prompt responses.
> 
> OK.  Now you realize that if you want the system time, you'd
> just say:
> 
>     my $now = time;
> 
> For a formatted person-friendly "now", use strftime() from the
> POSIX module:
> 
>     use POSIX qw(strftime);
>     my $now = strftime('%Y-%d-%m %H:%M:%S', localtime);

BZZT! Wrong.

POSIX explicitly provided the %c format to strftime, which is the
user's preferred representation.

(BTW, I presume %Y-%d-%m was a typo, and not related to the American
habit of writing dates as %m/%d/%y ? If it wasn't, that was a *very* bad
format to pick on...)

Ben

-- 
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~                   Jorge Luis Borges, 'The Babylon Lottery'


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

Date: Tue, 30 Nov 2004 18:04:01 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Unix commands and perl
Message-Id: <h9pu72-io4.ln1@osiris.mauzo.dyndns.org>


Quoth anno4000@lublin.zrz.tu-berlin.de (Anno Siegel):
> James Willmore  <jwillmore@fastmail.us> wrote in comp.lang.perl.misc:
> > On Mon, 29 Nov 2004 22:18:38 +0100, Michele Dondi wrote:
> > 
> > > On Mon, 29 Nov 2004 12:37:19 -0500, James Willmore
> > > <jwillmore@fastmail.us> wrote:
> > > 
> > >>[jim@localhost jim]$ perl -e 'print [getgrgid($<)]->[0],"\n";'
> > > 
> > > Not that I find it disturbing or incorrect, but what is this business
> > > of referencing and dereferencing?
> > > 
> > >   perl -le 'print +(getgrgid $<)[0]'
> > 
> > That's better.  I always have to work a little bit harder than I need to :-)
> 
> That's what getgrgid() returns in scalar context anyway:
> 
>     perl -le 'print scalar getgrgid $<'
> 
> is a little longer, but conceptually simpler.

Or, even clearer IMHO

use User::grent;

print getgr($<)->name;

Ben

-- 
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: 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 7476
***************************************


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