[24668] in Perl-Users-Digest
Perl-Users Digest, Issue: 6832 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 4 03:07:14 2004
Date: Wed, 4 Aug 2004 00:05:11 -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, 4 Aug 2004 Volume: 10 Number: 6832
Today's topics:
Re: any pointers please? combine words script <me@example.com>
Re: any pointers please? combine words script <me@example.com>
Best way to remove last word from a string <footnipple@indiatimes.com>
Re: Best way to remove last word from a string <noreply@gunnar.cc>
Re: Best way to remove last word from a string <jgibson@mail.arc.nasa.gov>
Re: Best way to remove last word from a string <segraves_f13@mindspring.com>
Re: Counting occurances of string A in string B, and ad <abigail@abigail.nl>
Re: Counting occurances of string A in string B, and ad (Anno Siegel)
Re: Counting occurances of string A in string B, and ad (Anno Siegel)
Fork within thread? <admin@asarian-host.net>
getting line between 2 patterns (mike)
Re: getting line between 2 patterns <noreply@gunnar.cc>
How to redirect STDOUT &STDERR? <luke@program.com.tw>
Re: How to redirect STDOUT &STDERR? <jgibson@mail.arc.nasa.gov>
Is that a way to get the child pid that start by an app (Mav)
join on space instead of comma <laura.hradowy@NOSPAM.mts.caaaaa>
Re: join on space instead of comma <noreply@gunnar.cc>
Kqueue interface module implementation (U. A. R. Ruirarchzatrea)
Re: Kqueue interface module implementation <uri@stemsystems.com>
Re: search/replace values from an array... <ebohlman@omsdev.com>
SOAP - undefined handler subroutine <spam@couts.org>
Understaing NET::LDAP <hillmw@ram.lmtas.lmco.com>
Re: Variable interpolation on STDIN ? <andrewpalmer@email.com>
Re: Variable interpolation on STDIN ? <bik.mido@tiscalinet.it>
Re: Variable interpolation on STDIN ? <bik.mido@tiscalinet.it>
Re: Variable interpolation on STDIN ? <bik.mido@tiscalinet.it>
Re: Your Guru Paul Graham is getting trashed on Slashdo (Aquila Deus)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 03 Aug 2004 15:00:37 -0400
From: steve_f <me@example.com>
Subject: Re: any pointers please? combine words script
Message-Id: <71ovg0lgndv6mqk569fpmbtg8qvlgmjqml@4ax.com>
On 03 Aug 2004 18:36:46 +0100, Brian McCauley <nobull@mail.com> wrote:
[ snip ]
>
>Hmmm... rolling your own templating system. I'll let someone else
>jump on you for that.
[ snip ]
hehe...yeah, that's my problem around here....I don't mean to do
the obvious but somehow I always do.
hey, thanks again Brian for your other comments...I'm still planning
to ask you a few more questions it just takes me a little time to
digest all the info around here.
------------------------------
Date: Tue, 03 Aug 2004 15:18:16 -0400
From: steve_f <me@example.com>
Subject: Re: any pointers please? combine words script
Message-Id: <quovg0lm0b2ed2nvdhoq9mgemdn2uf2e1r@4ax.com>
OK...I just want to say I really don't want to piss anyone off
here by cluttering this news group. Maybe I made a big mistake
by posting a super long program to begin with and I don't
want to keep posting replies if it clutters the group...I can
instead wait a bit and then ask specific questions later.
So basically I just want to thank everyone for their time
and I did learn a lot.
------------------------------
Date: Tue, 03 Aug 2004 22:33:33 GMT
From: "Guy Smiley" <footnipple@indiatimes.com>
Subject: Best way to remove last word from a string
Message-Id: <1pUPc.14476$wM.8388@twister.tampabay.rr.com>
Hello,
After googling and perldoc'ing, I'm still struggling to figure out the best
way to remove the last word from a string (without any line-ends or carriage
returns).
$output = "data1 data2 data3 data4";
Would like to see:
data1 data2 data3
I need to get this done soon and I have a long way to go before I understand
how to do this with a regex.
I'm also thinking that I could split the string at the spaces and construct
a new string by iterating through the array count minus 1. But this seems
like overkill.
my @datas = split(' ', $output);
for-loop
etc;
Any insight is greatly appreciated.
------------------------------
Date: Wed, 04 Aug 2004 01:00:00 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Best way to remove last word from a string
Message-Id: <2najmoFut66cU1@uni-berlin.de>
Guy Smiley wrote:
> After googling and perldoc'ing,
Which parts of the docs have you studied?
> I'm still struggling to figure out the best way to remove the last
> word from a string (without any line-ends or carriage returns).
>
> $output = "data1 data2 data3 data4";
>
> Would like to see:
>
> data1 data2 data3
>
> I need to get this done soon and I have a long way to go before I
> understand how to do this with a regex.
Then you'd better start right away, eh?
perldoc perlrequick
> I'm also thinking that I could split the string at the spaces and
> construct a new string by iterating through the array count minus
> 1. But this seems like overkill.
>
> my @datas = split(' ', $output);
> for-loop
> etc;
Well, if you start with splitting like that, you can make use of the
pop() function instead of iterating through the array. Doing so would
not be overkill IMO.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 03 Aug 2004 16:24:13 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Best way to remove last word from a string
Message-Id: <030820041624133215%jgibson@mail.arc.nasa.gov>
In article <1pUPc.14476$wM.8388@twister.tampabay.rr.com>, Guy Smiley
<footnipple@indiatimes.com> wrote:
> Hello,
>
> After googling and perldoc'ing, I'm still struggling to figure out the best
> way to remove the last word from a string (without any line-ends or carriage
> returns).
>
> $output = "data1 data2 data3 data4";
>
> Would like to see:
>
> data1 data2 data3
>
> I need to get this done soon and I have a long way to go before I understand
> how to do this with a regex.
How about $output =~ s/\s+\w+$//;
------------------------------
Date: Wed, 04 Aug 2004 00:11:53 GMT
From: "Bill Segraves" <segraves_f13@mindspring.com>
Subject: Re: Best way to remove last word from a string
Message-Id: <dRVPc.8412$Jp6.4072@newsread3.news.atl.earthlink.net>
"Guy Smiley" <footnipple@indiatimes.com> wrote in message
news:1pUPc.14476$wM.8388@twister.tampabay.rr.com...
<snip>
> After googling and perldoc'ing, I'm still struggling to figure out the
best
> way to remove the last word from a string (without any line-ends or
carriage
> returns).
>
> $output = "data1 data2 data3 data4";
>
> Would like to see:
>
> data1 data2 data3
>
> I need to get this done soon and I have a long way to go before I
understand
> how to do this with a regex.
$_ = "data1 data2 data3 data4";
s/ \w+$//;
print;
--
Bill Segraves
------------------------------
Date: 03 Aug 2004 18:33:32 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Counting occurances of string A in string B, and adding it to string B
Message-Id: <slrncgvmjs.ug6.abigail@alexandra.abigail.nl>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMCMXC September
MCMXCIII in <URL:news:cenrj5$ro6$2@mamenchi.zrz.TU-Berlin.DE>:
$$ Sandman <mr@sandman.net> wrote in comp.lang.perl.misc:
$$ > Let's say I have a string that goes like this:
$$ >
$$ > "A horse is a horse is a horse, on a horseman"
$$ >
$$ > and I want to count how many "horse" there is in the string. Well, that's easy,
$$ > by using:
$$ >
$$ > $_ = "A horse is a horse is a horse, on a horseman";
$$ > my $nr;
$$ > $nr++ for /horse/ig;
$$ > print $nr;
$$ > __END__
$$ > Out: 4
$$ >
$$ > Now, I would like add a number to each word that contains the string horse,
$$ > this is where I am lost.
$$ >
$$ > Basically, what I want to output is this:
$$ >
$$ > "A horse (1) is a horse (2) is a horse (3), on a horseman (4)"
$$ >
$$ >
$$ > Note that it should be "horseman (4)" not "horse (4)man".
$$
$$ my $n = 0;
$$ s/(\w*horse\w*)/do { $n ++; "$1 ($n)"}/eg;
No need for the 'do { }'.
s/(\w*horse\s*)/$n ++; "$1 ($n)"/eg;
will do fine.
Abigail
--
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$==-2449231+gm_julian_day+time);do{until($=<$#r){$_.=$r[$#r];$=-=$#r}for(;
!$r[--$#r];){}}while$=;$,="\x20";print+$_=>September=>MCMXCIII=>=>=>=>=>=>=>=>'
------------------------------
Date: 3 Aug 2004 20:35:57 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Counting occurances of string A in string B, and adding it to string B
Message-Id: <ceosvd$je7$1@mamenchi.zrz.TU-Berlin.DE>
Abigail <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMCMXC September
> MCMXCIII in <URL:news:cenrj5$ro6$2@mamenchi.zrz.TU-Berlin.DE>:
> $$ my $n = 0;
> $$ s/(\w*horse\w*)/do { $n ++; "$1 ($n)"}/eg;
>
>
> No need for the 'do { }'.
>
> s/(\w*horse\s*)/$n ++; "$1 ($n)"/eg;
>
> will do fine.
You're right. The substitution part in s///e is, in effect, a do-block.
No need to wrap it in another one.
Anno
------------------------------
Date: 3 Aug 2004 20:46:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Counting occurances of string A in string B, and adding it to string B
Message-Id: <ceotis$je7$2@mamenchi.zrz.TU-Berlin.DE>
Brian McCauley <nobull@mail.com> wrote in comp.lang.perl.misc:
> Uri Guttman <uri@stemsystems.com> writes:
[...]
> >
> > JR> $_ = "A horse is a horse is a horse, on a horseman";
> > JR> $n = 0;
> > JR> s/\b(horse\w*)/"$1 (" . ++$n .")"/ge;
> >
> > since you can put as much code as you want with /e (which uses the last
> > value of the code block), make it easier to read:
> >
> > s/\b(horse\w*)/$n++ ; "$1 ($n)"/ge;
>
> TIMTOWDI
>
> s/\b(horse\w*)/$1 (@{[ ++$n ]})/g;
Ah, that doesn't need /e. The action can also go on the matching side.
s/\b(horse\w*)(?{ $n ++ })/$1 ($n)/g;
Anno
------------------------------
Date: Wed, 4 Aug 2004 01:45:19 +0200
From: "Mark" <admin@asarian-host.net>
Subject: Fork within thread?
Message-Id: <QdudnY2f9-oKvo3cRVn-pg@giganews.com>
Hello,
Using Perl 5.8.3, is it possible (c.q. safe) to fork within a thread? I have
a daemon which uses threads. Due to some instability, I had to serialize the
threads. So I was wondering whether fork is at all thread-safe, so I can
fork after all.
Thanks,
- Mark
------------------------------
Date: 3 Aug 2004 21:38:17 -0700
From: s99999999s2003@yahoo.com (mike)
Subject: getting line between 2 patterns
Message-Id: <dfd17ef4.0408032038.1d7d5c94@posting.google.com>
hi
i have a file like this:
2004nddjjf99jdlkdf <---- 99 is at character position 11 to 12
2004abcdefghijklnmnopqrstuvwxyz
2004ldfhanvsduhkjgndfnspqiekfnv
2003nmvkdmcnfjfbndmdkvndnmvkdbn
2004nddgdf99dkgfjs
i wanted to get the text in between the 2 lines that have the number
"99" at the
11th and 12th position.
i looked at FAQ ,
perl -ne 'print if /START/ .. /END/' file1 ...
how can i define the START and END such that it must check for
character position 11 and 12 to look for 99 ??
thanks.
------------------------------
Date: Wed, 04 Aug 2004 08:18:25 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: getting line between 2 patterns
Message-Id: <2nbde5Fum05pU1@uni-berlin.de>
mike wrote:
> i have a file like this:
>
> 2004nddjjf99jdlkdf <---- 99 is at character position 11 to 12
> 2004abcdefghijklnmnopqrstuvwxyz
> 2004ldfhanvsduhkjgndfnspqiekfnv
> 2003nmvkdmcnfjfbndmdkvndnmvkdbn
> 2004nddgdf99dkgfjs
>
> i wanted to get the text in between the 2 lines that have the
> number "99" at the 11th and 12th position.
>
> i looked at FAQ ,
>
> perl -ne 'print if /START/ .. /END/' file1 ...
>
> how can i define the START and END such that it must check for
> character position 11 and 12 to look for 99 ??
/^.{10}99/
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 4 Aug 2004 02:21:30 +0800
From: "news.hinet.net" <luke@program.com.tw>
Subject: How to redirect STDOUT &STDERR?
Message-Id: <ceol6m$oib$1@netnews.hinet.net>
How to redirect STDOUT &STDERR to screen and a logfile?
------------------------------
Date: Tue, 03 Aug 2004 12:46:45 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: How to redirect STDOUT &STDERR?
Message-Id: <030820041246457151%jgibson@mail.arc.nasa.gov>
In article <ceol6m$oib$1@netnews.hinet.net>, news.hinet.net
<luke@program.com.tw> wrote:
> How to redirect STDOUT &STDERR to screen and a logfile?
Check out the module IO::Tee and the FAQ 'How do I print to more than
one file at once'.
------------------------------
Date: 3 Aug 2004 14:56:01 -0700
From: mluvw47@yahoo.com (Mav)
Subject: Is that a way to get the child pid that start by an application?
Message-Id: <dfaafecd.0408031356.7b043a31@posting.google.com>
Hi, there
I have a perl script on windows that try to lanuch a
command(devenv.com);However, the process still start an process
(devenv.exe) that I am trying to get the pid, so I can kill it later.
I able to get the pid for devenv.com, but not devenv.exe, and when
I kill devenv.com, devenv.exe will be zombie.
Here is my code:
...
@args = ("\"$devPath\\devenv.com\" ..\\Solution\\my.sln /build
Debug");
$pid = open my $proc, "@args |"; #Able to get the pid for devenv.com
...
Any idea?
Thanks,
Mav
------------------------------
Date: Tue, 3 Aug 2004 23:13:37 -0500
From: "LHradowy" <laura.hradowy@NOSPAM.mts.caaaaa>
Subject: join on space instead of comma
Message-Id: <SnZPc.1991$La.5645@news1.mts.net>
Right now I have a perl script that takes a comma separated file and adds a
couple of things to it as will as takes away the data at the end.
I have done this the hard way, by saving a file in excel and a comma
separated file, then ftp it over, dos2ux file >file1.
And this is the outcome BEFORE I run my perl script.
3xxxx18,00 0 02 00,TELN NOT
3xxxx22,00 0 03 11,CUST HAS >
Then after all that I run my perl script against it prompts user for input,
adds some data, then greps file for certain things, and creates 3 files.
What I want to do is elinate the first part of saving it as a comma
separated file. I belive I can do this in perl, but I can not split on
spaces since I have spaces that I need to be part of a column. So, (how to
explain) instead of the above mention where there is a comma, I need to
split this file, based on criteria, and also add a comma between the
columns, so it looks like above...
This is the file I get before I save it as a comma separated file.
3xxxx33 00 0 00 21 CUSTOMER HAS
> 1
3xxxx63 00 0 01 07 CUSTOMER HAS
> 1
3xxxx75 00 0 02 09 CUSTOMER HAS
> 1
3xxxx85 00 0 12 09 TELN NOT BILL
3xxxx28 00 0 02 00 TELN NOT BILL
yada...
I want to avoid this step, how do I change my perl script to reflect this
instead of a comma.
Remember in the 2 and third fields there are spaces that I need.
OUTCOME
3xxxx33,BUILDING1,ROOM2,00 0 00 21,CUSTOMER HAS > 1
3xxxx66,BUILDING1,ROOM2,00 0 01 07,CUSTOMER HAS > 1
3xxxx75,BUILDING1,ROOM2,00 0 02 09,CUSTOMER HAS > 1
3xxxx85,BUILDING1,ROOM2,00 0 12 09,TELN NOT BILL
SCRIPT
*****************************
#!/opt/perl/bin/perl
use strict;
use warnings;
system ("clear"); #Clear the screen
my $acode = "204";
print "Enter BLD: ";
chomp (my $bld =<STDIN>);
my $CAPbld = uc($bld);
my $bld4=substr $CAPbld,0,4; #Pull first 4 char out of BLD for naming of
file
print "Enter Room: ";
chomp (my $room = <STDIN>);
my $CAProom = uc($room);
open my $fc, ">$bld4.cust_has" or die "$bld4.cust_has: $!";
open my $ft, ">$bld4.teln_not" or die "$bld4.teln_not: $!";
open my $fo, ">$bld4.PRTDIST.err" or die "$bld4.PRTDIST.err: $!";
while (<>) {
chomp; # Will remove the leading , or new line
my @a = split /,/, $_, -1;
my $f = /TELN/ ? $ft : /CUST/? $fc : $fo;
print $f join "," => $acode.$a[0],$CAPbld, $CAProom, $a[1], $a[2], "\n";
}
close $fc;
close $ft;
close $fo;
## Modify the cust_has file and pull only the first column.
my $fc_name = "$bld4.cust_has";
open (my $fc, $fc_name) or die "$fc_name:$!";
open my $fcC, ">$bld4.cust_has.tn" or die "$bld4.cust_has.tn: $!";
while (<$fc>) {
chomp;
my ( $FirstField,@Rest)=split /,/;
print $fcC join (",","'$FirstField',",)."\n";
}
close fc;
close fcC;
## Modify the teln_not file to take off last column
## File is now ready for report making.
my $fc_name2 = "$bld4.teln_not";
open (my $fc, $fc_name2) or die "$fc_name2:$!";
open my $fcT, ">$bld4.teln_not-1" or die "$bld4.teln_not-1: $!";
while (<$fc>) {
chomp;
my ( $FirstField1,$SecondField1,$ThirdField1,$FourthField1,@Rest)=split /,/;
print $fcT join
(",","$FirstField1","$SecondField1","$ThirdField1","$FourthField1",)."\n";
}
close fc;
close fcT;
`mv $bld4.teln_not-1 $bld4.teln_not`;
------------------------------
Date: Wed, 04 Aug 2004 08:02:11 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: join on space instead of comma
Message-Id: <2nbcfiFuo2uuU1@uni-berlin.de>
LHradowy wrote:
>
> And this is the outcome BEFORE I run my perl script.
> 3xxxx18,00 0 02 00,TELN NOT
> 3xxxx22,00 0 03 11,CUST HAS >
<snip>
> What I want to do is elinate the first part of saving it as a comma
> separated file. I belive I can do this in perl, but I can not
> split on spaces since I have spaces that I need to be part of a
> column.
Can't you split on instances of multiple spaces?
> So, (how to explain) instead of the above mention where there is a
> comma, I need to split this file, based on criteria, and also add a
> comma between the columns, so it looks like above...
>
> This is the file I get before I save it as a comma separated file.
> 3xxxx33 00 0 00 21 CUSTOMER HAS > 1
> 3xxxx63 00 0 01 07 CUSTOMER HAS > 1
> 3xxxx75 00 0 02 09 CUSTOMER HAS > 1
> 3xxxx85 00 0 12 09 TELN NOT BILL
> 3xxxx28 00 0 02 00 TELN NOT BILL
<snip>
> my @a = split /,/, $_, -1;
s/\s+//;
my @a = split /\s{3,}/;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 3 Aug 2004 20:40:25 -0700
From: millueradfa@yahoo.com (U. A. R. Ruirarchzatrea)
Subject: Kqueue interface module implementation
Message-Id: <efa550f7.0408031940.62ceab1a@posting.google.com>
Hello,
I have been trying to get a Kqueue module written for Perl with XS
that would allow the Kqueue event notification facility to be accessed
from Perl. Kqueue is a scalable event notification facility often
found on BSD OSs that allows you to recieve events from sockets for
instance, and corrects the performance limitations of select, allowing
for multiplexed servers to be written which can scale to very large
numbers of connections. It does the same thing as epoll on Linux but
does have a broader range of applications and features than epoll.
Having a module avialable to access Kqueue would be of use to anyone
wanting to write scalable network code on BSD OSs.
Has anyone out there looked into implemented a Kqueue module?
I was looking into doing it myself, but got confused how to do it. The goal
is for a Kqueue module written which can be contributed to CPAN so
other people who need to use Kqueue do not have to reinvent the wheel.
The Kqueue module should i think basically a straightforward
mapping of the kqueue and kevent functions and the kevent structures
to Perl. Later I can writing a higher level OO IO::Kqueue interface
around the Kqueue module, which would be no problem for me, since that
wouldnt directly use XS.
Of course, the Kqueue module involves writing an XS wrapper and that
is where I am completely confused as to how to properly implement the
interface.
I am sure for a Perl XS guru this would probably take a short bit to
implement with a few lines of code, but despite my reading the xs
documentation it is still beyond my understanding how to to implement
the wrapper.
Documentation for kqueue can be found in the kqueue man page "man
kqueue", the man pages can also be read online if you search for
kqueue.
Is there anyone out there who might be interested and know how to
write the code to do this?
I do have some of the files from my attempt including an XS wrapper
and and a .pm file in the following archive:
http://www.geocities.com/millueradfa/Kqueue.tar.gz. The archive also
includes the kqueue manual page and a sample kqueue echo server I
found. The man pages explains the kqueue API. A pointer to an array of
kevent structures is passed to kevent().
Perhaps this would map to
perl as a reference to an array containing arrays whos elements would
contain the values in the kevent structure. I have written some
documentation of what I was thinking of for the API for the module at
the end of the .pm file. Here is a synopsis of the API i was
considering, this is the low level API and will be wrapper with a
higher level interface later in IO::Kqueue:
use Kqueue;
($kq, $errno)=kqueue();
$timeout=12;
$filter='EVFILT_READ';
$flags='EV_ADD';
$fflags='';
$data='';
$udata='';
@kevent=($sockid, $filter, $flags, $fflags, $data, $udata);
@changelist=(\@kevent);
$changelist=\@changelist;
@eventlist=();
$eventlist=\@eventlist;
($errorval, $errno)=kevent($kq, $changelist, $eventlist, $timeout);
I think Changelist contains any changes to the configuration, eventlist, is used
to return pending events.
I am posting some of the documentation for Kqueue here and the
incomplete XS file I need help with getting to work. For the full
files (including .pm) you can look at the archive download I
previously referenced.
part of Kqueue man page (for full manpage look at :
http://people.freebsd.org/~jmg/kqueue.man.html)
SYNOPSIS
#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
int
kqueue(void);
int
kevent(int kq, const struct kevent *changelist, int nchanges,
struct kevent *eventlist, int nevents,
const struct timespec *timeout);
EV_SET(&kev, ident, filter, flags, fflags, data, udata);
The kevent structure is defined as:
struct kevent {
uintptr_t ident; /* identifier for this event */
short filter; /* filter for event */
u_short flags; /* action flags for kqueue */
u_int fflags; /* filter flag value */
intptr_t data; /* filter data value */
void *udata; /* opaque user data identifier */
};
RETURN VALUES
kqueue() creates a new kernel event queue and returns a file
descriptor.
If there was an error creating the kernel event queue, a value of
-1 is
returned and errno set.
kevent() returns the number of events placed in the eventlist, up
to the
value given by nevents. If an error occurs while processing an
element
of the changelist and there is enough room in the eventlist, then
the
event will be placed in the eventlist with EV_ERROR set in flags
and the
system error in data. Otherwise, -1 will be returned, and errno
will be
set to indicate the error condition. If the time limit expires,
then
kevent() returns 0.
Kqueue.xs:
#include "ppport.h"
#include <sys/event.h>
#include <sys/types.h>
#include <sys/time.h>
#include "const-c.inc"
MODULE = Kqueue PACKAGE = Kqueue
INCLUDE: const-xs.inc
int
kqueue ()
int
kevent (kq, changelist, nchanges, eventlist, nevents, timeout)
int kq
const struct kevent *changelist
int nchanges
struct kevent *eventlist
int nevents
const struct timespec *timeout
Thank you for any assistance in this.
U. A. R. Ruirarchzatrea
------------------------------
Date: Wed, 04 Aug 2004 05:06:44 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Kqueue interface module implementation
Message-Id: <x73c33bigg.fsf@mail.sysarch.com>
>>>>> "UARR" == U A R Ruirarchzatrea <millueradfa@yahoo.com> writes:
UARR> I have been trying to get a Kqueue module written for Perl with
UARR> XS that would allow the Kqueue event notification facility to be
UARR> accessed from Perl. Kqueue is a scalable event notification
UARR> facility often found on BSD OSs that allows you to recieve
UARR> events from sockets for instance, and corrects the performance
UARR> limitations of select, allowing for multiplexed servers to be
UARR> written which can scale to very large numbers of connections. It
UARR> does the same thing as epoll on Linux but does have a broader
UARR> range of applications and features than epoll.
UARR> Having a module avialable to access Kqueue would be of use to
UARR> anyone wanting to write scalable network code on BSD OSs.
UARR> Has anyone out there looked into implemented a Kqueue module? I
UARR> was looking into doing it myself, but got confused how to do
UARR> it. The goal is for a Kqueue module written which can be
UARR> contributed to CPAN so other people who need to use Kqueue do
UARR> not have to reinvent the wheel.
check out using libevent (at http://monkey.org/~provos/libevent/)
instead and wrapping that in perl via xs/swig/inline. that will be more
effective in that it gives you /dev/poll, kqueue(2), select(2), poll(2)
and epoll(4) support already and with one api wrapper you get all in
perl. i would be willing to help out with this as i have written and
wrapped event loops and done some (small) xs work (actually in swig).
you shouldn't post the kqueue api here as it can be found on the
net. and proposing a perl api for it is too early. first check out
libevent and think about wrapping that. then get the extending and
embedding perl book and read that. then work on the api (i can help
there for sure). also look at event.pm (on cpan) and its api. there is
plenty to do before you create the api and the actual wrapper code.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 3 Aug 2004 19:44:37 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: search/replace values from an array...
Message-Id: <Xns953A96CACAF9Febohlmanomsdevcom@130.133.1.4>
Jim Gibson <jgibson@mail.arc.nasa.gov> wrote in
news:020820041326456159%jgibson@mail.arc.nasa.gov:
> "Or else it doesn't, you know. The name of the song is called
> 'Haddock's Eyes' ."
>
> "Oh, that's the name of the song, is it?" Alice said, trying to feel
> interested.
>
> "No, you don't understand," the Knight said, looking a little vexed.
> "That's what the name is called . The name really is 'The Aged Aged
> Man' ."
>
> "Then I ought to have said 'That's what the song is called?'" Alice
> corrected herself.
>
> "No, you oughtn't: that's quite another thing! The song is called
> 'Ways and Means' : but that's only what it's called , you know!"
>
> "Well, what is the song, then?" said Alice, who was by this time
> completely bewildered.
>
> "I was coming to that," the Knight said. "The song really is
> 'A-sitting on a Gate' : and the tune's my own invention."
I don't think you can fully appreciate this in all its profundity unless
you have an assembler background.
------------------------------
Date: Wed, 04 Aug 2004 01:02:12 GMT
From: Aaron Couts <spam@couts.org>
Subject: SOAP - undefined handler subroutine
Message-Id: <slrnch0dr5.f8d.spam@waimea.local>
I had SOAP working last night and now it's mysteriously not working. I'm
trying to get a test script going with SOAP::Lite, Apache, and mod_perl.
Whenever I call my routine, I Apache gives me:
-------------
[Tue Aug 3 19:29:24 2004] [error] Undefined subroutine
&SOAP::ServerDemo::handler called.
-------------
Here's my ServerDemo.pm (straight from the SOAP::Transport::HTTP::Apache doc):
-------------
package ServerDemo;
use SOAP::Transport::HTTP::Apache;
sub handler {
my $safe_classes = {
Calculator => undef,
};
SOAP::Transport::HTTP::Apache->handler($safe_classes);
}
package Calculator;
sub new {
bless {}, shift;
}
sub handle_request {
my ($self, $headers, $body, $envelopeMaker) = @_;
$body->{extra_stuff} = "heres some extra stuff";
foreach my $header (@$headers) {
$header->{extra_stuff} = "heres some more extra stuff";
$envelopeMaker->add_header(undef, undef, 0, 0, $header);
}
$envelopeMaker->set_body(undef, 'myresponse', 0, $body);
}
1;
-------------
Here's my client:
-------------
#!/usr/bin/perl
use SOAP::Lite;
print SOAP::Lite
-> uri('http://10.0.131.98/Calculator')
-> proxy('http://10.0.131.98/soap')
-> handle_request
-> result;
-------------
And here's my Apache config (i've already verified that mod_perl is working):
-------------
<IfModule mod_perl.c>
<Location /soap>
SetHandler perl-script
PerlHandler SOAP::ServerDemo
</Location>
</IfModule>
-------------
I've tried this several different ways, and I always get a message that
the handler subroutine isn't defined, even though I can see it right there
in ServerDemo.pm. Last night I got Paul Kulchenko's farenheit-celcius
converter working with a very similar client, but then I made a change and
it stopped working. Any help would be greatly appreciated.
Thanks,
Aaron Couts
--
To contact me via email, substitute
'aaronc' for 'spam' in my address.
http://www.towerdata.com
------------------------------
Date: Tue, 03 Aug 2004 13:54:09 -0500
From: Michael Hill <hillmw@ram.lmtas.lmco.com>
Subject: Understaing NET::LDAP
Message-Id: <410FDF51.F5862E1B@ram.lmtas.lmco.com>
I have a LDAP query like:
my $basedn = "ou=people,o=myhost.com";
my $scope = "sub";
my $filter = "manager=uid=fred,ou=people,o=myhost.com";
$searchobj = $conn->search( base=>$basedn, scope=>$scope,
filter=>$filter, attrs=>$attrs );
my $max = $searchobj->count;
## iterate through the hash
for($i = 0 ; $i < $max ; $i++)
{
my $entry = $searchobj->entry($i);
foreach my $attr ($entry->attributes)
{
#iterate over the fields
}
}
Only thing is that I'd like to limit the records being returned.
The object "manager" could look like either
ex1:
uid=fred,ou=people,o=myhost.com
uid=fred_boss,ou=people,o=myhost.com
uid=fred_boss_boss,ou=people,o=myhost.com
ex2:
uid=works_for_fred,ou=people,o=myhost.com
uid=fred,ou=people,o=myhost.com
uid=fred_boss,ou=people,o=myhost.com
uid=fred_boss_boss,ou=people,o=myhost.com
So .... since I am searching for "uid=fred,ou=people,o=myhost.com" I get
both rows.
I can limit the output in the "foreach" step, but I'd like to limit the
number of records matching the search in the filter so the script
processes quicker.
Anyone have any idea how to enhance the filter further?
Mike
------------------------------
Date: Wed, 4 Aug 2004 00:25:14 -0500
From: "Andrew Palmer" <andrewpalmer@email.com>
Subject: Re: Variable interpolation on STDIN ?
Message-Id: <mo_Pc.1372$zc1.664@fe40.usenetserver.com>
Here's another thought. If you want true shell-like evaluation, you could
literally pass your input to the shell.
> my $fileToCheck = <STDIN>;
$fileToCheck=`echo $fileToCheck`;
> chomp ($fileToCheck);
> if (-e $fileToCheck)
> {
> print "Not Found\n";
> }
This should expand "~" as well as expand environment variables and do other
shell things. However, this is kind of quick and dirty. Not as safe as
$fileToCheck =~ s/\$(\w+)/$ENV{ $1}/g;
>
> The problem is that I want to allow the user to specify the file with
> environment variables in some way. For example, to check if x.pl is
present
> under the home directory, the user should be able to give
>
> $HOME/x.pl
>
> However, it seems that we cannot interpolate like this while reading from
> STDIN (or from a file)? Am I missing something ?
>
> I tried $ENV{HOME}/x.pl also, but it also gave the same error :
>
> No such file or directory
>
> TIA
>
> --
> Abhinav
------------------------------
Date: Tue, 03 Aug 2004 22:48:13 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Variable interpolation on STDIN ?
Message-Id: <u76vg0tjadu75o90iso7qmegvekjvh8fve@4ax.com>
On Tue, 03 Aug 2004 17:00:52 +0530, Abhinav
<matrix_calling@yahoo.dot.com> wrote:
>my $fileToCheck = <STDIN>;
>chomp ($fileToCheck);
>if (-e $fileToCheck)
>{
> print "Not Found\n";
>}
Side note: I suppose that should be !-e or s/if/unless/, etc.
>The problem is that I want to allow the user to specify the file with
>environment variables in some way. For example, to check if x.pl is present
>under the home directory, the user should be able to give
>
>$HOME/x.pl
>
>However, it seems that we cannot interpolate like this while reading from
>STDIN (or from a file)? Am I missing something ?
Yes: environment variables expansion is done by the shell, and there's
no reason it should take place while reading from a FH.
>I tried $ENV{HOME}/x.pl also, but it also gave the same error :
Because that is read literally, as is natural to expect. FWIW I would
never do anything like that, but then you may achieve what you want by
means of:
s/\$\(w+)/$ENV{$1}/ge;
e.g.:
# export foo=bar
# perl -lpe 's/\$(\w+)/$ENV{$1}/'
This is $foo, isn't it?
This is bar, isn't it?
Oops, I forgot /e and it still works out of interpolation!
Michele
--
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
"perl bug File::Basename and Perl's nature"
------------------------------
Date: Tue, 03 Aug 2004 22:48:16 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Variable interpolation on STDIN ?
Message-Id: <e66vg0dhg2o2ico4gkh4dj8qm4bk1sflgl@4ax.com>
On Tue, 03 Aug 2004 17:58:58 +0530, Abhinav
<matrix_calling@yahoo.dot.com> wrote:
>(ab) newschema- perl test.pl
>$HOME/x.pl
>Not Found: $HOME/x.pl
>
>There is no variable substitution happening here..
And there MUST NOT be...
Michele
--
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
"perl bug File::Basename and Perl's nature"
------------------------------
Date: Tue, 03 Aug 2004 22:48:19 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Variable interpolation on STDIN ?
Message-Id: <ustvg0dbj12ca7ldmb32f0scahp42pn86f@4ax.com>
On 3 Aug 2004 11:44:41 GMT, Julius Plenz <usenet@plenz.com> wrote:
>> I tried $ENV{HOME}/x.pl also, but it also gave the same error :
>
>Did you also try "$ENV{HOME}/x.pl"?
He means that he tried writing that ON STDIN, not literally in the
program source...
Michele
--
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
"perl bug File::Basename and Perl's nature"
------------------------------
Date: 3 Aug 2004 17:31:27 -0700
From: aquila_deus@yahoo.co.uk (Aquila Deus)
Subject: Re: Your Guru Paul Graham is getting trashed on Slashdot.
Message-Id: <c5cfac8f.0408031631.71f77154@posting.google.com>
mikecoxlinux@yahoo.com (Mike Cox) wrote in message news:<3d6111f1.0407290030.17075cd9@posting.google.com>...
> After writing an article trashing java, and C++, notable LISP guru
> Paul Graham is getting roasted on slashdot. Apart from AutoCAD and
> Emacs, what has LISP done anyway? Most real work is done in C++ or C
> in the case of systems development. Perl is useful, but only for
> dynamic web content or simple sysadmin scripts. Most slashdotters
> think the same!
Nah, I just joined THE ATC (Air Traffic Control) project using Perl as
the main language!
from http://sourceforge.net/projects/mratc
"replacement to today's antiquated ATC system"
We haven't started coding yet, but hot discussion is already there
(see our two mailing-lists). WE NEED MORE DEVELOPERS!
<snip>
------------------------------
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 6832
***************************************