[23520] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5729 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 30 09:05:51 2003

Date: Thu, 30 Oct 2003 06: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           Thu, 30 Oct 2003     Volume: 10 Number: 5729

Today's topics:
    Re: Can't do setuid and file permision denied errors (Chris)
    Re: Can't do setuid and file permision denied errors (Chris)
    Re: converting text data (Vumani Dlamini)
    Re: DHCP client tool (Peter Lohmeier)
    Re: difference between defined & exists <nobull@mail.com>
    Re: DOS window. <spikeywan@bigfoot.com.delete.this.bit>
        Equivalent of "ls -t" ? <stanb@panix.com>
    Re: Equivalent of "ls -t" ? <nobull@mail.com>
    Re: Equivalent of "ls -t" ? (Anno Siegel)
    Re: Equivalent of "ls -t" ? <abigail@abigail.nl>
    Re: fork process to handle fifo input (Ole)
    Re: fork process to handle fifo input <nobull@mail.com>
    Re: iteration number <HelgiBriem_1@hotmail.com>
    Re: Java with apache from perl script? <HelgiBriem_1@hotmail.com>
    Re: multiline regular expression, is it possible? <bernard.el-haginDODGE_THIS@lido-tech.net>
        Parsing of blocks (e.g. foo { bar }) <torh+news@removethisbitbeforethedot.bogus.net>
    Re: Parsing results of ps? (Anno Siegel)
    Re: Perl and IIS - script runs but 'The page cannot be  <HelgiBriem_1@hotmail.com>
    Re: regex for stripping HTML (Anno Siegel)
    Re: runtime load of code <Dov.Levenglick@motorola.com>
    Re: runtime load of code (Anno Siegel)
    Re: runtime load of code <nobull@mail.com>
    Re: Sort two dimensional array with multiple keys (Anno Siegel)
    Re: tie problem <bart.lateur@pandora.be>
    Re: Video::Capture example? <zentara@highstream.net>
    Re: What am I doing wrong?! (Tony Walker)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 30 Oct 2003 02:34:12 -0800
From: chrisw@lu.csi.com.ph (Chris)
Subject: Re: Can't do setuid and file permision denied errors
Message-Id: <14142d1f.0310300234.aa5a592@posting.google.com>

Abigail <abigail@abigail.nl> wrote in message news:<slrnbpvtjf.fk5.abigail@alexandra.abigail.nl>...
> Chris (chrisw@lu.csi.com.ph) wrote on MMMDCCXI September MCMXCIII in
> <URL:news:14142d1f.0310281705.661c55be@posting.google.com>:
> \\  
> \\  I'm a newbie with perl scripts
> \\
> \\  I have a chpass.pl which is being executed by a change password web
> \\  utility page.
> 
> And what makes you think this is a good idea? Would you let your
> kids drive in NASCAR races right after they learned how to use
> how to steer?
> 
Well, i'm still a starter, at least I know now..

> Changing passwords via a web interface is a dumb thing to do.
> Changing the passwords by directly opening /etc/shadow is dangerous.
> Doing that with a program written in a language you just started
> to use sounds like a bloody stupid idea to me.

When the  pasword changer works, I supposed to make security access on
the web page..it should be only accessed by authorized user.. I still
dont know how but I'll figure it out..

> 
> On the boxes I've adminned, there has only be one way for a user
> to set a new password: appear in person, and if needed with an ID.
> 
> 
> 
> Abigail


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

Date: 30 Oct 2003 03:06:06 -0800
From: chrisw@lu.csi.com.ph (Chris)
Subject: Re: Can't do setuid and file permision denied errors
Message-Id: <14142d1f.0310300306.6a0718d3@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnbpuk6d.gld.tadmc@magna.augustmail.com>...
> Chris <chrisw@lu.csi.com.ph> wrote:
> 
> > I'm a newbie with perl scripts 
> 
> 
> No problem. Everybody has to start somewhere.
> 
> 
> > I'm having
> > problem running my copied script to my server. 
> 
> 
> What server?
> 
> Most uses of Perl do not require a server at all, so the least
> you could do was tell us what _kind_ of server you are
> dealing with: SMTP, NNTP, FTP, HTTP...
> 

yeah, this is supposed to be dial-up authentication server..

> 
> > I have a chpass.pl which is being executed by a change password web
> > utility page. 
> 
> 
> Oh. Must be question about using Perl in the CGI environment then?
> 
> Have you already seen what the Perl FAQ has to say about CGI programming?
> 
>    perldoc -q CGI
> 
> 
> 
> The easiest programming is single user on the command line.
> 
> CGI programming is a bit more advanced, as it adds issues of
> multitasking, security and sometimes performance, that would 
> not normally need to be considered.
> 
> Changing passwords is yet more advanced, but in the area of
> Operating Systems, rather than Perl.
> 
> Changing passwords through a CGI interface scares me to death!
> 
> And that is what you want to take on as your very first
> Perl program?
> 
> Gulp.
> 
> 
> 1) Learn Perl before learning a new application area, such as CGI.
> 
> 2) _Why_ do you think you want this? 

This is what they suggest me so I just need to make it work..
> 
> It is *profoundly* dangerous you know...

Heah, I agree... I Was thinking of making security on the page..
When the  pasword changer works, I supposed to make security access on
the web page..it should be only accessed by authorized user.. I still
dont know how but I'll figure it out..


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

Date: 30 Oct 2003 00:35:48 -0800
From: dvumani@hotmail.com (Vumani Dlamini)
Subject: Re: converting text data
Message-Id: <4b35f3c9.0310300035.7042da95@posting.google.com>

Thanks a lot for the comments, they really helped me.

Vumani


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

Date: 30 Oct 2003 03:24:11 -0800
From: pelohh@compuserve.de (Peter Lohmeier)
Subject: Re: DHCP client tool
Message-Id: <ebbdbbfe.0310300324.442d438e@posting.google.com>

James Willmore <jwillmore@remove.adelphia.net> wrote in message news:<20031029111929.200f7de8.jwillmore@remove.adelphia.net>...
> On 29 Oct 2003 05:32:35 -0800
> pelohh@compuserve.de (Peter Lohmeier) wrote:
> 
> > want to test DHCP responses ...
> > 
> > Do you mean, it is possible to send a DHCP request with Active State
> > Perl under W2k ??
> 
> Not sure.  Try using 'ppm' to 'search' for a DHCP module.

I found one in the news. 

----------------------------
From: "nudnav" <francis.van.dun@pandora.be>
Newsgroups: comp.lang.perl.modules
Subject: ANNOUNCE: Net-DHCP-Packet v0.1
Lines: 137
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4807.1700
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700
Message-ID: <aCKS7.3838$Up1.526@afrodite.telenet-ops.be>
Date: Sat, 15 Dec 2001 16:10:46 GMT
NNTP-Posting-Host: 213.224.170.139
X-Complaints-To: abuse@pandora.be
X-Trace: afrodite.telenet-ops.be 1008432646 213.224.170.139 (Sat, 15
Dec 2001 17:10:46 MET)
NNTP-Posting-Date: Sat, 15 Dec 2001 17:10:46 MET
Organization: Telenet Internet


The uploaded file
Net-DHCP-Packet-0.1.tar.gz
has entered CPAN as
file: $CPAN/authors/id/F/FV/FVANDUN/Net-DHCP-Packet-0.1.tar.gz
size: 5661 bytes
----------------------------

But I'm not shure wether it works with my Active State Perl
Answer to "perl -v" is
"This is perl, version 5.005_03 built for MSWin32-x86-object ......."


> 
> > 
> > And if so, would it be possible to set a special MAC Address also ??
> > 
> 
> Huh?  That's a very difficult task to perform.  The MAC address is a
> hardware address.  So, you _could_ use different NIC's to change the
> MAC address - but that's not practical :-)  
> 
> I'm thinking that you _could_ do it in Perl, but it's a very difficult
> task.
> 
> What is it you're trying to test?

Simply I want to prove whether a DHCP request for a specific Client PC
- and that isn't actually my PC - gets the right answer from the
Server.
Therefore I have to fake the MAC Address of the Client. 

… But if I think about that … obviously the answer to that request
would get lost, because although my scanning PC has a different MAC
than the client to fake it would never listen to the answer, right ??

In that case I have to change to the promiscuous mode of a ‘sniffer'
with perl and filter the right packets for the faked client. That
might be the main problem. :-/

May perl be mighty to do that ??

 .pl


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

Date: 30 Oct 2003 08:46:24 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: difference between defined & exists
Message-Id: <u9ekwvt5ah.fsf@wcl-l.bham.ac.uk>

palam_analog@yahoo.co.in (Palaniappan) writes:

> What is the difference between 'defined' operator
> and 'exists' operator?

Even if you are a newcommer to the Perl community you should still try
to give as well as take.  You have, in fact, already contributed
something my choosing a good subject line for this thread.  Well done,
that already puts you above the median.

You could, however, have done more.

If there is something about the explaination of these operators in the
reference manual that is unclear then please tell us exactly what.

Newbies are uniquely qualified to tell us where and how the manual is
unclear and so help the community improve it.  This is something that
experienced Perl users are unable to do because we know what the
manual is trying to say already.

Please take the opportunity afforded you by your _inexperience_ to
contribute while you can.

BTW: Don't (yet) bother trying to understand what exists() (and
delete()) mean when applied to array elements - it's not really
useful[1].  

The exists() operator is only really useful applied to hash
elements[2].

[1] It has to do with pseudo-hashes which are deprocated anyhow.

[2] And symbolic function references but that's only relevant if you
are writing AUTOLOAD handlers.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 30 Oct 2003 09:43:22 -0000
From: "Richard S Beckett" <spikeywan@bigfoot.com.delete.this.bit>
Subject: Re: DOS window.
Message-Id: <bnqmil$noq$1@newshost.mot.com>

Oh well. It does work differently from anything else I'm used to, maybe it's
because it's still a FE of W98. I do have a SE somewhere, but I was waiting
until it broke before I installed that.

It's a shame that microsoft not supporting their own hardware in later
windows versions is actually stopping me from upgrading. In fact it's
incredible, because the hardware is so robust, I think it might last
forever! ;-)

Thanks Guys.
-- 
R.
GPLRank +79.699




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

Date: Thu, 30 Oct 2003 12:59:29 +0000 (UTC)
From: Stan Brown <stanb@panix.com>
Subject: Equivalent of "ls -t" ?
Message-Id: <bnr1vh$gap$1@reader2.panix.com>

I need to get a list of all the files in a given directory, sorted in
oldest -> newest into an array for processing. 

What's a good way to do this?


-- 
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
						-- Benjamin Franklin


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

Date: 30 Oct 2003 13:17:36 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Equivalent of "ls -t" ?
Message-Id: <u91xsuuaof.fsf@wcl-l.bham.ac.uk>

Stan Brown <stanb@panix.com> writes:

> I need to get a list of all the files in a given directory,

Use readdir (and its related functions).

> sorted 

See FAQ: How do I sort an array by (anything)?

> oldest -> newest into an array for processing. 

The function to get the age of a file is -M

> What's a good way to do this?

To sort something (in this case filenames) according to some extrinsic
or computed property (in this case the age of the file with that name)
you can use the Schwartzian Transform (as per the FAQ).

<fish>

opendir my $dh, $dir or die $!;

my @files =  map { $_->[0] }
             sort { $b->[1] cmp $a->[1] }
             map  { [ $_, -M "$dir/$_" ] }
             readdir $dh;

</fish>

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 30 Oct 2003 13:28:42 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Equivalent of "ls -t" ?
Message-Id: <bnr3ma$sb8$3@mamenchi.zrz.TU-Berlin.DE>

Stan Brown  <stanb@panix.com> wrote in comp.lang.perl.misc:
> I need to get a list of all the files in a given directory, sorted in
> oldest -> newest into an array for processing. 
> 
> What's a good way to do this?

Here is one:

    my $dir = '.';
    opendir my $d, $dir or die "bah $dir: $!";
    my @l = sort { -M $a <=> -M $b } readdir( $d);
    print join "\n", @l, '';

This is fine for small directories.  For lots of files you may consider
a Schwartzian transform to reduce the overhead of "-M" calls. (See
"perldoc -q sort" for that.)

Anno


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

Date: 30 Oct 2003 13:53:31 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Equivalent of "ls -t" ?
Message-Id: <slrnbq25ur.a97.abigail@alexandra.abigail.nl>

Stan Brown (stanb@panix.com) wrote on MMMDCCXII September MCMXCIII in
<URL:news:bnr1vh$gap$1@reader2.panix.com>:
\\  I need to get a list of all the files in a given directory, sorted in
\\  oldest -> newest into an array for processing. 


ls -t orders them from newest to oldest. Anyway, here's a solution
(oldest to newest).

my $dir = ".";
opendir my $dh => $dir or die;
my @files = map {substr $_ => 8}
            sort 
            map {sprintf "%08x$_" => (stat) [9], $_} grep {! /^\./} readdir $dh;
closedir $dh;



Abigail
-- 
$;                                   # A lone dollar?
=$";                                 # Pod?
$;                                   # The return of the lone dollar?
{Just=>another=>Perl=>Hacker=>}      # Bare block?
=$/;                                 # More pod?
print%;                              # No right operand for %?


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

Date: 30 Oct 2003 01:56:58 -0800
From: oviaudmurat@web.de (Ole)
Subject: Re: fork process to handle fifo input
Message-Id: <c640408c.0310300156.69dd06eb@posting.google.com>

Ben Morrow <usenet@morrow.me.uk> wrote in message news:<bnoto5$k9a$1@wisteria.csv.warwick.ac.uk>...
> oviaudmurat@web.de (Ole) wrote:
> 
> > hi everybody,
>  
> > Now i have the following code: ( the program forks 5 processes that
> > work on the input of the named pipe.  after having collected a
> > certain amount of information, the processes save the data to a
> > file. )
> 
> I have to confess that I don't really understand the description
> above; however, I shall offer what help I can...
> 
> > #!/usr/bin/perl -w
> > use POSIX;
> > use strict;
> 
> You want
>   use subs qw/wait_zombies saveReport/;
> here. You alse want to choose one of under_scores and studlyCaps and
> stick to it.
> 
> > my $pid;
> > my $childId;
> > my $child_pids = [ ];
> > our $zombies = 0;
> 
> Why 'our'? The only reason is if you need to get a this var from
> outside this file... as far I I can see, you have only one file.
> 
> You want
>   $\ = "\n";
> here: for why see below where I deal with your print()s.
> 
> > ##########################################################################
> > 
> > for ( my $num = 0; $num < 5; $num++ ) {
> 
> This is C. Perl would be:
> 
>   for my $num (0..5) {
> 
> > 	if (( $pid = fork ( ) ) > 0 ) { # parent process
> 
> Where do you check if the fork failed?
> 
> Better:
>   $pid = fork;
>   defined $pid or die "can't fork: $!";
>   if($pid) { # parent
> 
> > 		push ( @$child_pids, $pid );
> > 	}elsif ( $pid == 0 ) {
> 
> ...in which case this can just be
>   } else { # kid
>  
> > 		my $FIFO;
> > 		my $i = 1;
> > 		my $reports = [];
> > 		my $my_pid = getpid ( ) ||die "Cannot getpid ( ) :
> > 		$!";
> 
> It is clearer to use 'or' rather than ||, as then you do not need the
> () for getpid.
> 
> The current process's pid is available in $$: see perldoc perlvar.
> 
> > 		while ( 1 ) {
> 
> Where do you exit this loop?
> 
> > 		  open ( $FIFO, "</dev/ipt_fifo" );
> 
> No need for the brackets.
> As Tad would say :) always, yes *always* check the return of open.
> 
>     open $FIFO, "</dev/ipt_fifo" or die "can't open fifo: $!";
> 
> > 		  while ( <$FIFO> ) {
> >                     # analyze log data... ( left here ) #
> > 		    push( @$reports, $_ );
> > 		    print $my_pid . " : " . $i . "--Size of \$reports\t:\t" .
> > scalar( @$reports ) . "\n";
> 
>   print "$$ : $i--Size of \$reports\t:\t" . @$reports;
> 
> No need for \n as you set $\ above: see perldoc perlvar.
> 
> > 		    if (( $i % 1024 ) == 0 ) {
> 
> $i will never be greater that 1024: no need for modulus.
> 
>   if($i == 1024) {
> 
> > 		      saveReport ( $reports,$my_pid );
> > 		      undef ( $reports );
> > 		      print "OK\n";
> > 		      $i = 0;
> > 		    }
> > 		    $i++;
> > 		  }
> > 		  close ( $FIFO );
> 
> close can fail as well.
> 
>    close $FIFO or die "colsing fifo failed: $!";
> 
> > 		}
> > 	      }
> >       }
> > 
> > wait_zombies ( $pid );
> 
> $pid holds the pid of the last child you forked. Why are you passing
> only this?
> 
> > sub wait_zombies {
> >   my $pid = $_[ 0 ];
> 
>     my $pid = shift;
> 
> >   if ( $pid > 0 ) {
> 
> Is this an attempt to make up for not checking the return value of
> fork()? Otherwise it is pointless...
> 
> >     my $chId;
> >     do {
> >       $chId = waitpid( -1, 0 );
> >       print "Caught child no $chId\n";
> >     }until ( $chId == - 1 );
> >   }
> > }
> > 
> > 
> > 
> > sub saveReport  {
> > 	my $reports = $_[ 0 ];
> > 	my $my_pid  = $_[ 1 ];
> 
>   my $reports = shift;
>   my $my_pid  = shift;
> 
> or
> 
>   my ($reports, $my_pid) = @_;
> 
> according to taste.
> 
> > 	open ( FH, ">>log_fork_childno_$my_pid.log" );
> 
>   open FH, ">>log_fork_childno_${my_pid}.log" 
>     or die "can't open log no. $my_pid: $!";
> 
> > 	print "saving reports [PID = $my_pid]";
> > 	foreach ( @$reports ) {
> 
> /Please/ try and be consistent. Do you spell it 'for' or 'foreach'?
> 
> > 	  print ".";
> > 	  print FH $_;
> > 	}
> > 	close ( FH );
> 
> ... or die "can't close log $my_pid: $!";
> 
> > }
> > ##################################################################
> > 
> > Now i have 2 problems:
>  
> > 1.) How do I trap e.g. a "kill -9" command, directed to the parent
> > process in order to collect to child processes before quiting. Now
> > the child processes get init for as parent.
> 
> You can't. That's the point of SIGKILL: it can't be trapped. If you
> want to trap other signals, look at %SIG in perlvar.
> 

So, if i "use wait_zombies", the child processes are terminated, er ..
waited for automatically or do i have to define a reaper function ?


> > 2. ) I recognize a strange behaviour: for a while, the processes
> > collect data from syslog through the fifo as they should. But then,
> > it seems that syslog is generating approx 200 entires per
> > second. But i think that it has to do with process synchronization.
> 
> I'm afraid I don't understand what you mean... but you could be right:
> you certainly have sync problems.
> 
> > Questions:
> >
> > 1. ) Is it possible that, if two processes try to read
> > simultaneously from the named pipe or fifo, they lock themselves
> > somehow ?
> 
> Each byte fed into the pipe comes out exactly once, to exactly one of
> the processes reading it. Absolutely no guarantees about which. It is
> generally a bad idea to have more than one process on either end of a
> fifo.
> 
> > 2. ) How can manage it to have only one child process trying to read
> > from the fifo ?
> 
> a. Use a lockfile to synchronise access.

But what if syslog wants to write to the fifo while me having locked
the pipe ?


> b. Have a 'reader' process that reads data from the fifo and passes it
>    to the other children for processing.
> c. Don't fork()... :)

But how have children without fork ?
   
                      fifo
                        |
                        | parents reads from
                ________|__________
                |parent ( reader )|
                |_________________|
                        /\  
                       /  \ parent sends data to children
                      /    \
                 child1 ..  childn      ( children process data and
save it )

> 
> > I would be very thankful if someone might help me out here.  I need
> > this filter daemon, because it is the topic of the final examination
> > of my training.
> 
> Well, you must examine your own conscience about that... I would
> suggest you need to at least read the question a bit more carefully to
> find out what is *actually* required, in particular, what these
> multiple child processes are supposed to do.
There is no question. Here in germany the system lacks structured
education.
You must ( or may ) choose what you want to do for the final
excamination. BTW, i'm not studying computer science ( not yet ). I'm
training as "Fachinformatiker Systemintegration" some kind of network
plugger.
So i decided to implement a traffic analyzing system, running on 
linux, iptables and syslog-ng and perl. Initially i thought it would
suffice
to have a cron execute a perl script every 10 minutes in order to
extract logfileinformation and save it away to postgres. But i saw
that the logfiles were growing too fast (  ~ 0.5M / sec ). So i
decided to implement a daemon that
will attach to a pipe, filtering the logfiles "on the fly".

Thanks for MUCH inspiration to enhancing the code ( or to make it
reasonable ).

Greetings Ole .

> 
> Ben


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

Date: 30 Oct 2003 12:34:49 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: fork process to handle fifo input
Message-Id: <u9ad7iucnq.fsf@wcl-l.bham.ac.uk>

Please trim quoted material leaving just what is relevant to provide context.

oviaudmurat@web.de (Ole) writes:

> Ben Morrow <usenet@morrow.me.uk> wrote in message news:<bnoto5$k9a$1@wisteria.csv.warwick.ac.uk>...
> > oviaudmurat@web.de (Ole) wrote:
> > 
[ snip 160 lines that were not necessary to give context ]

> >  
> > > 1.) How do I trap e.g. a "kill -9" command, directed to the parent
> > > process in order to collect to child processes before quiting. Now
> > > the child processes get init for as parent.
> > 
> > You can't. That's the point of SIGKILL: it can't be trapped. If you
> > want to trap other signals, look at %SIG in perlvar.
> > 
> 
> So, if i "use wait_zombies", the child processes are terminated, er ..
> waited for automatically or do i have to define a reaper function ?

In general you only have to define a reaper if you want timely destruction of
zombies.

[ snip 19 more irrelevant qouted lines ]

> > > 2. ) How can manage it to have only one child process trying to read
> > > from the fifo ?
> > 
> > a. Use a lockfile to synchronise access.
> 
> But what if syslog wants to write to the fifo while me having locked
> the pipe ?

syslog neither knows nor cares what mechanisms your processes are
using to suncronise their actions.

> > c. Don't fork()... :)
> 
> But how have children without fork ?

You don't.  By don't fork Ben was saying just have a single process.
There's no apparent reason for using a multiprocess model here.


> > b. Have a 'reader' process that reads data from the fifo and passes it
> >    to the other children for processing.

>    
>                       fifo
>                         |
>                         | parents reads from
>                 ________|__________
>                 |parent ( reader )|
>                 |_________________|
>                         /\  
>                        /  \ parent sends data to children
>                       /    \
>                  child1 ..  childn      ( children process data and
> save it )

Yes that's Ben's (b).

> > > I would be very thankful if someone might help me out here.  I need
> > > this filter daemon, because it is the topic of the final examination
> > > of my training.
> > 
> > Well, you must examine your own conscience about that... I would
> > suggest you need to at least read the question a bit more carefully to
> > find out what is *actually* required, in particular, what these
> > multiple child processes are supposed to do.
>
> There is no question. Here in germany the system lacks structured
> education.
> You must ( or may ) choose what you want to do for the final
> excamination. BTW, i'm not studying computer science ( not yet ). I'm
> training as "Fachinformatiker Systemintegration" some kind of network
> plugger.
> So i decided to implement a traffic analyzing system, running on 
> linux, iptables and syslog-ng and perl. Initially i thought it would
> suffice
> to have a cron execute a perl script every 10 minutes in order to
> extract logfileinformation and save it away to postgres. But i saw
> that the logfiles were growing too fast (  ~ 0.5M / sec ). So i
> decided to implement a daemon that
> will attach to a pipe, filtering the logfiles "on the fly".

I think you are missing the point here. 

When Ben said "find out what is *actually* required, in particular,
what these multiple child processes are supposed to do", he was (I
believe) saying that as has as you've shown us there is no reason for
using more than a single process to implement you daemon.

Is this running on a 8-CPU box?  If not your processes will all be
contending for the same CPUs so will most likely be slower than a
single process.

Even if your box has 8CPUs, do you really want this daemon to be
able to occupy multiple CPUs?

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 30 Oct 2003 11:15:52 +0000
From: Helgi Briem <HelgiBriem_1@hotmail.com>
Subject: Re: iteration number
Message-Id: <0is1qvkti0svn364se271sraqc81g6bu1t@4ax.com>

On Tue, 28 Oct 2003 23:08:35 -0800, "Michael Vilain
<vilain@spamcop.net>" wrote:

>In article <3f9f61bf$1@dnews.tpgi.com.au>, "Jack" <jaddo@yahoo.com.> 
>wrote:
>
>> is there a perl default variable which holds the number of iteration for the
>> 'foreach' statement
>> foreach my $key ( sort keys %data) {
>
>Not that I'm aware of.  Because of this, if I need any sort of index, I 
>use a "for" loop instead.

for and foreach behave identically down to the tiniest detail in Perl
There is *no* difference between them excapt that using one or the 
other may make the code look more like English in certain situations.



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

Date: Thu, 30 Oct 2003 10:57:49 +0000
From: Helgi Briem <HelgiBriem_1@hotmail.com>
Subject: Re: Java with apache from perl script?
Message-Id: <ver1qvkn5ccufth9qadhp43jcllrmh0rbc@4ax.com>

On 29 Oct 2003 09:26:16 -0800, i5513@hotmail.com (i5513) wrote:

>Hi, I'm running Apache server with mod_perl active.
>
>I can run my script from command line and all is fine, but when I run
>my script from navigator, it doesn't run fine because my script is:
>
>system "java program_java";

>How can I do Apache to run java programs?
>
CGI is run under a special user with restricted rights and
an empty path variable.

You should always, yes *always* check the results
of system operations and return the error ($! for 
internal processes, $? for daughter process).

Give it the full path to java and the program.

my $java = '/full/path/to/java';
my $program_java = '/full/path/to/program_java';
system ($java $program_java) == 0 or die $?;


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

Date: Thu, 30 Oct 2003 08:46:35 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: multiline regular expression, is it possible?
Message-Id: <Xns94246338DD8E1elhber1lidotechnet@62.89.127.66>

(Bill) wrote: 

[...]

> Interesting...the last time I came across this was with parsing the
> 'clit' formatted pages
  ^^^^^^


Come on, admit it, you made that name up! ;-)


-- 
Cheers,
Bernard


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

Date: Thu, 30 Oct 2003 12:36:39 +0000
From: Tor Houghton <torh+news@removethisbitbeforethedot.bogus.net>
Subject: Parsing of blocks (e.g. foo { bar })
Message-Id: <pan.2003.10.30.12.36.38.391132@removethisbitbeforethedot.bogus.net>

Hi,

I'm wondering if there is a more elegant way of parsing "blocks" of data.

I have a configuration file, thus:

   # comment
   
   some.host.name {
      ; another comment
      /etc/hostname.fxp0
      /etc/hosts
      /etc/mail
   }

And I currently parse this using the following code:

    while(<CONF>) {
       next if(/^\s*(\#|;)|^\s*$/);
       if(m#(\S+)\s+{# .. m#}#) {
          $HOST=$1 if $1;
          if(!/\{|\}/) {
             print "add: $HOST ",$_;
          }
       }
    }

Before I go "all out" and complete this section of the code using the
above technique, I was wondering if there was other (better) ways of doing
this (for one, I'm not sure how to catch out any errors in the file, for
instance:

    some.host.here {
       another.host {
          /usr
          /opt
       }
       /etc
       /var/mail
    }

 .. here the current code fails miserably. Mind you, I'm probably the only
one going to use this, so that may not be such a big deal :-> )

Thanks!

Tor


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

Date: 30 Oct 2003 10:33:40 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Parsing results of ps?
Message-Id: <bnqpe4$oe4$1@mamenchi.zrz.TU-Berlin.DE>

Gregory Toomey  <nospam@bigpond.com> wrote in comp.lang.perl.misc:
> It was a dark and stormy night, and Marv managed to scribble:


> > I need to capture PID number from each line into a variable while in a

[...]

> Here's a snippet of code (based on linux ps) that gives you a start:
> 
> my($pid,$tname,$etime,$cmd,$emin,$ehour,$background);                   

Some of these variables aren't used in your code.  Those that are used
are only used inside the loop body, so the declaration should be in the
body too (principle of smallest possible scope).

> for (split '\n', qx(ps -u $> -o pid,tname,etime,cmd --no-headers)) {

There is no need for split, qx() does that automatically in list context:

for ( qx(ps -u $> -o pid,tname,etime,cmd --no-headers) ) {

>   #unpack ps line 
>   ($pid, $tname, $etime,$cmd) = unpack "a5 x a11 x a8 x a200",$_;
>   # decode a few fields
>   $etime =~ /((\d*):)?(\d*):(\d*)$/;
>   $ehour  = $2;
>   $emin   = $3;
>   # is this process running in the background
>   $background=/\?/;
>   #etc 
> }

Anno


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

Date: Thu, 30 Oct 2003 09:27:20 +0000
From: Helgi Briem <HelgiBriem_1@hotmail.com>
Subject: Re: Perl and IIS - script runs but 'The page cannot be displayed'
Message-Id: <1am1qvsvj7v320rs7dtd8mctpblkq5adcj@4ax.com>

On Tue, 28 Oct 2003 02:31:47 +0000 (UTC), Ben Morrow
<usenet@morrow.me.uk> wrote:

>> Where does the STDERR go and when is it written to? Is there a
>> missing error log I can't see.
>
>That is a question about your web server... at least with Apache,
>stderr is logged to error_log.

While your advice is all correct and good, I strongly suggest
you stop responding to this troll who is clearly here only
to get a rise out of people by acting like a complete moron.


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

Date: 30 Oct 2003 13:06:54 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: regex for stripping HTML
Message-Id: <bnr2de$sb8$1@mamenchi.zrz.TU-Berlin.DE>

DOV LEVENGLICK  <Dov.Levenglick@motorola.com> wrote in comp.lang.perl.misc:
> "Michael Vilain " wrote:

[DOV's top-posting re-arranged]

> >   $value =~ s/\<[^\<]+\>//g;
> >
> >and I'm trying to parse it out and figure out why it works.  First off, 
> >some questions:
> >
> >- why escape the "<"?  It's not one of the meta characters that has 
> >special meaning in a regex.
> 
> you have to escape < because it can be used as a search delimiter

This is nonsense.  What are you talking about?  And don't top-post.

Anno


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

Date: Thu, 30 Oct 2003 14:41:59 +0200
From: DOV LEVENGLICK <Dov.Levenglick@motorola.com>
Subject: Re: runtime load of code
Message-Id: <3FA10717.6040305@motorola.com>

you are probably getting that because require will only retrieve the 
first copy of a subroutine and disregard the other subroutines with the 
same name

Alythh wrote:

>OK, it works
>
>foreach $address (@addresses)
>{
>    $mod = $modules{$address};
>
>    require $mod;
>...
>}
>
>... it just complains about:
>Subroutine process_page redefined at ... line 20.
>Subroutine action_on_page redefined at ... line 48.
>
>but it's OK enough for me.
>
>thanks
>
>Alessandro Magni
>  
>

-- 
Regards,
Dov Levenglick




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

Date: 30 Oct 2003 13:13:01 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: runtime load of code
Message-Id: <bnr2ot$sb8$2@mamenchi.zrz.TU-Berlin.DE>

[another of DOV's top-postings re-arranged]

DOV LEVENGLICK  <Dov.Levenglick@motorola.com> wrote in comp.lang.perl.misc:
> Alythh wrote:
> 
> >OK, it works
> >
> >foreach $address (@addresses)
> >{
> >    $mod = $modules{$address};
> >
> >    require $mod;
> >...
> >}
> >
> >... it just complains about:
> >Subroutine process_page redefined at ... line 20.
> >Subroutine action_on_page redefined at ... line 48.
> 
> you are probably getting that because require will only retrieve the 
> first copy of a subroutine and disregard the other subroutines with the 
> same name

That is mere speculation, and it's wrong.  In fact, the messages appear
because require does *not* ignore later re-definitions of the same
subroutine.

Please don't post stuff you just made up of thin air.

Anno


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

Date: 30 Oct 2003 13:20:22 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: runtime load of code
Message-Id: <u9wuamsvzd.fsf@wcl-l.bham.ac.uk>

DOV LEVENGLICK <Dov.Levenglick@motorola.com> vomits TOFU in our faces:

> >Subroutine process_page redefined at ... line 20.
> >Subroutine action_on_page redefined at ... line 48.

> you are probably getting that because require will only retrieve the
> first copy of a subroutine and disregard the other subroutines with
> the same name

Nonsense.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 30 Oct 2003 11:46:24 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Sort two dimensional array with multiple keys
Message-Id: <bnqtmg$rff$1@mamenchi.zrz.TU-Berlin.DE>

Milkweed <chris.mielke@drake.edu> wrote in comp.lang.perl.misc:
> I am trying sort an multi-dimensional array with three elements in
> each "row".
> 
> Here's a look at a small section of input data:
> 
> 207.28.198.86 10.36.1.121 0310291642
> 207.28.198.86 10.36.1.121 0310291753
> 207.28.201.113 10.77.2.241 0310291642
> 207.28.200.113 10.75.2.87 0310291642
> 207.28.199.86 10.76.1.80 0310291642
> 207.28.198.104 10.1.3.153 0310291642
> 207.28.198.86 10.36.1.121 0310291324
> 207.28.199.104 10.2.2.77 0310291642
> 207.28.195.33 10.2.4.111 0310291642
> 
> These are timestamped NAT translations from a firewall.
> What I want to do is sort this data by element 0 (global IP) as the
> primary key and element 2 (timestamp) as the secondary key so I can
> keep a historical record of NAT translations for a given global IP.
> 
> I can't seem to get the sort to work. Here is a copy of what I have
> tried so far:
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> use Net::Telnet::Cisco;
> use Data::Sorting qw( :basics :arrays );

I'm not acquainted with that module, but your sort problem is so
straight-forward, I'd first try a direct solution.

> 
> ...
> 
> foreach (@xlate) { # @xlate is populated by a SNMP call to the
> firewall
>     next unless /^Global/;
>     my ($global, $local) = (split /\s/)[1,3];
>     push @entries, [$global,$local,$timestamp]; 
> # each row of @entries now looks like the sample data above

Unlikely.  The variable $timestamp isn't assigned a value.

> }
> 
> #Sort entries by IP (primary key) and date (secondary key) and print
> output
> my @ordered = sorted_array( @entries,
>     { engine=> 'packed', sortkey=>$_[0][0] },
>     sortkey=>$_[0][2] );
> #my $i = 0;
> #keys my %h = @history;
> #@h{ sort map pack('C4 A x N' => $->[0] =~
> /(\d+)\.(\d+)\.(\d+)\.(\d+)/,
> #    $_->[2], $i++) => @history } = @history;
> #my @ordered = @h{ sort keys %h };
> open NEW, ">xlate-ordered"
>     or die "Could not open xlate-ordered for writing: $!\n";
> for my $row (@ordered) {
>     print NEW "@$row\n";
> }
> 
> As you can see I have tried using the "indexed sort" method from "A
> Fresh Look at Efficient Perl Sorting" as well as the Data::Sorting
> module with no success. Help with either option would be much
> appreciated!

As noted, you don't *need* any special methods for this sort.  You
may be able to speed things up a bit, but the first step should be
to get it right.

Assume your data is given like this (what it should be, but isn't, after
the loop over @xlate):

    my @entries = (
        [ qw( 207.28.198.86 10.36.1.121 0310291642)],
        [ qw( 207.28.198.86 10.36.1.121 0310291753)],
        [ qw( 207.28.201.113 10.77.2.241 0310291642)],
        [ qw( 207.28.200.113 10.75.2.87 0310291642)],
        [ qw( 207.28.199.86 10.76.1.80 0310291642)],
        [ qw( 207.28.198.104 10.1.3.153 0310291642)],
        [ qw( 207.28.198.86 10.36.1.121 0310291324)],
        [ qw( 207.28.199.104 10.2.2.77 0310291642)],
        [ qw( 207.28.195.33 10.2.4.111 0310291642)],
    );

For sorting, compare any two IPs as strings.  If they are equal,
compare the timestamps as numbers.  The result is your sorted list:

    my @sorted = sort 
        { $a->[ 0] cmp $b->[ 0] or $a->[ 2] <=> $b->[ 2] } 
        @entries;

    print "@$_\n" for @sorted;

Anno


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

Date: Thu, 30 Oct 2003 08:48:12 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: tie problem
Message-Id: <mtj1qvogs7a5j26gprq81sk12f4o9ec6j6@4ax.com>

Richard Churchill wrote:

> I was using this
>code inside a package and declaring the modules outside of the package, for
>some reason Fcntl was not picked up correctly, but SDBM was. 

The reason for the difference is that Fcntl uses a procedural interface,
so the names must be imported into your current package -- or you can
use fully qualified names, like Fcntl::O_RDWR; while tie uses an OO
interface, and import isn't necessary. The methods are still in a
completely separate package (class) whatever you do, and it's good that
way.


-- 
	Bart.


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

Date: Thu, 30 Oct 2003 08:57:51 -0500
From: zentara <zentara@highstream.net>
Subject: Re: Video::Capture example?
Message-Id: <4u32qvgthijulq4baguj941i6a9jhr8g7p@4ax.com>

On Wed, 29 Oct 2003 15:15:27 +0000 (UTC), Stan Brown <stanb@panix.com>
wrote:

>I'm writing a perl script to capture images from some cameras, and make
>mpes out of them on Linux.
>
>I't basicly working using system() calls to v4lctl, but that is slowing
>things dow, spawning a seperate task for each capture.
>
>I've found the Video::Captur module, and I think it's the way to go.
>However it has no documentation for the calls, and the example programs
>have no comments.
>
>Could anyone point me to a working example of capturing an image using
>this? I suspect I jyst need to traslate a couple of v4;ctl commands to the
>corect syntax for using this module. EG:

Here is a Tk camera capture program is wrote. The biggest obstacles are
making sure the camera syncs, and converting the raw BGR data to RGB.
There are a couple of different ways you can do this, I used a technique
of reversing the data, then flipping it with Imager. Imager also has a
more direct matrix method, but I think it was a bit slower that way.
Read "perldoc Imager::Transformations".

#!/usr/bin/perl
use warnings;
use strict;
use Video::Capture::V4l;
use Imager;
use Tk;
use Tk::JPEG;
use MIME::Base64;

my $timestamp;
my $temp = '';

sub grab_one {
    $temp      = '';
    $timestamp = scalar(localtime);
    $timestamp =~ tr/ /_/;
    $| = 1;

    my $grab = new Video::Capture::V4l
      or die "Unable to open Videodevice: $!";

    # the following initializes the camera for NTSC
    my $channel = $grab->channel(0);
    my $tuner   = $grab->tuner(0);
    $tuner->mode(1);
    $channel->norm(1);
    $tuner->set;
    $channel->set;

    my $frame = 0;
    my $fr    = $grab->capture( $frame, 320, 240 );
    my $count = 0;

    for ( 0 .. 1 ) {
        my $nfr = $grab->capture( 1 - $frame, 320, 240 );
        $grab->sync($frame) or die "unable to sync";

        unless ( $count == 0 ) {

            # save $fr now, as it contains the raw BGR data
            $temp = '';
            open( JP, '>', \$temp ) or die $!;
            print JP "P6\n320 240\n255\n";    #header
            $nfr = reverse $nfr;
            print JP $nfr;
            close JP;

            my $img = Imager->new();
            $img->read( data => $temp, type => 'pnm' )
              or warn $img->errstr();
            $img->flip( dir => "hv" );
            $img->write( data => \$temp, type => 'jpeg' )
              or warn $img->errstr;
        }
        $count++;
        $frame = 1 - $frame;
        $fr    = $nfr;
    }
}

grab_one();

my $mw = MainWindow->new();
my $image = $mw->Photo( -data => encode_base64($temp) );
$mw->Label( -image => $image )->pack( -expand => 1, -fill => 'both' );

my $label =
  $mw->Label( -text => $timestamp )->pack( -side => 'top', -padx => 3 );

my $center = $mw->Frame->pack( -anchor => 'center' );
$center->Button( -text => 'Quit', -command => [ destroy => $mw ] )
  ->pack( -side => 'left', -padx => 3 );
$center->Button( -text => 'Update', -command => \&update )
  ->pack( -side => 'left', -padx => 3 );
$center->Button( -text => 'Save', -command => \&save_it )
  ->pack( -side => 'left', -padx => 3 );

MainLoop;

sub save_it {
    open( JP, "> $timestamp.jpg" ) or die $!;
    print JP $temp;
    close JP;
    $label->configure( -text => "$timestamp.jpg  SAVED" );
    $label->update;
}

sub update {
    grab_one();
    $label->configure( -text => "$timestamp" );
    $label->update;
    $image->configure( -data => encode_base64($temp) );
    $image->update;
    $mw->update;
}

__END__


Our body's 20 milligrams of beta radioactive Potassium 40
emit about 340 million neutrinos per day, which go at well-nigh
lightspeed to the ends of the universe!..even thru the earth. 


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

Date: 30 Oct 2003 02:12:54 -0800
From: tony.walker@dhl.com (Tony Walker)
Subject: Re: What am I doing wrong?!
Message-Id: <72461e59.0310300212.1a948130@posting.google.com>

Guys,

Thanks for all the help! Can't believe it was a chomp() that was my problem. 

A question related to one of the responses:

I'm now trying

for (my $i=0..@entry)
or
for (@entry) 


And neither seem to be working??

Thanks again,

Tony


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

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


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