[17934] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 94 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 19 00:05:46 2001

Date: Thu, 18 Jan 2001 21: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)
Message-Id: <979880712-v10-i94@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 18 Jan 2001     Volume: 10 Number: 94

Today's topics:
    Re: $FindBin::Bin for modules <johnlin@chttl.com.tw>
    Re: Call C function in XS from C function in the same X <john@imining.com.tw>
    Re: Child processes don't clean up (defunct processes l <mischief@velma.motion.net>
    Re: excel to csv tools <bart.lateur@skynet.be>
    Re: FAQ 9.15:   How do I decode a CGI form? <callgirl@la.znet.com>
    Re: FAQ 9.15:   How do I decode a CGI form? (Damian James)
    Re: FAQ 9.15:   How do I decode a CGI form? <callgirl@la.znet.com>
    Re: Flock flaky over NFS how about fcntl? <rick.delaney@home.com>
        Hello.  I'm back. jdf@pobox.com
    Re: HELP: httpS protocol (https and NOT http)! <rick.delaney@home.com>
        How do I page output in the debugger on Win32? <sdf@expertune.com>
    Re: How to Create a Perl Shared Library (.so file) ? hmug@my-deja.com
    Re: How to Create a Perl Shared Library (.so file) ? Lee.Lindley@bigfoot.com
    Re: how to match a space character <ren.maddox@tivoli.com>
    Re: how to match a space character <ren.maddox@tivoli.com>
        How to search for a certain entity's value in a xml fil <kdinh@commerce-tv.com>
    Re: How to search for a certain entity's value in a xml (Garry Williams)
        lookbehind in s///g <bart.lateur@skynet.be>
    Re: lookbehind in s///g (Abigail)
    Re: lookbehind in s///g <ren.maddox@tivoli.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 19 Jan 2001 10:31:29 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: $FindBin::Bin for modules
Message-Id: <94891j$72o@netnews.hinet.net>

> "John Lin" writes:
>
> > My module needs to know where itself is stored because it wants
> > to open a data file stored in the same directory.

<nobull@mail.com> wrote:
> A module can access its own filename using __FILE__.

"Rafael Garcia-Suarez" wrote:
> Use the %INC hash, described in perlvar.

Great!!!  Thank you very much.  My testing results are:

When main.pl is evoked in the same directory

in A.pm: __FILE__ = A.pm
in A.pm: $INC{'A.pm'} = A.pm

When main.pl is evoked in different directory

in A.pm: __FILE__ = /john/lib/A.pm
in A.pm: $INC{'A.pm'} = /john/lib/A.pm


Just like the main script position can be derived from
  $0  and  __FILE__  , that's what FindBin.pm does,
my suggestion is to extend FindBin.pm to do the same
thing for modules.  That would be more complete.

What do you think about that?

Thank you.

John Lin





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

Date: Fri, 19 Jan 2001 11:45:00 +0800
From: "John" <john@imining.com.tw>
Subject: Re: Call C function in XS from C function in the same XS file
Message-Id: <948di0$eln@netnews.hinet.net>

I followed your advice and it worked fine.
Thank you very much.

But I found another problem.
Running C code with Inline module seems very slow.
Maybe it has to take some time to parse the C code.
The major reason that makes me use C to extend Perl is I have to some system
level actions in a very fast manner.
When I use Inline module, it seems that I have to give up the speed.


Brian Ingerson <active_ingy@my-deja.com> wrote in message
news:946l2r$t5n$1@nnrp1.deja.com...
> In article <93tos9$ium@netnews.hinet.net>,
>   "John" <john@imining.com.tw> wrote:
> > Hi:
> >
> > I have a function ShowCounter() in WebGet.xs
> > When I call ShowCounter() from another function in WebGet.xs, I get the
> > following error.
> >
> > perl: error in loading shared libraries:
blib/arch/auto/WebGet/WebGet.so:
> > undefined symbol: ShowCounter
> >
> > But I can call ShowCounter() from my perl program that use module
WebGet.
> > I really have to call ShowCounter() in other C functions in WebGet.xs.
> > How should I do?
>
> The Inline module, which allows you to write C extensions without having
> to bother with XS (or compiling for that matter) comes with a Cookbook
> of examples. One of the examples answers the question you have asked.
>
> Here's another complete program from a paper I wrote recently. It shows
> how to call the same function from Perl and C, and also how to keep a
> function from binding to Perl by declaring it static.
> --------------------------------------------------
>     print "9 + 5 = ", add(9, 5), "\n";
>     print "SQRT(9^2 + 5^2) = ", pyth(9, 5), "\n";
>     print "9 * 5 = ", mult(9, 5), "\n";
>
>     use Inline C => <<'END_C';
>     int add(int x, int y) {
>         return x + y;
>     }
>     static int mult(int x, int y) {
>         return x * y;
>     }
>     double pyth(int x, int y) {
>         return sqrt(add(mult(x, x), mult(y, y)));
>     }
>     END_C
>
> This produces:
>
>     9 + 5 = 14
>     SQRT(9^2 + 5^2) = 10.295630140987
>     Can't locate auto/main/mult.al in @INC ...
> ----------------------------------------------------
>
> HTH, Brian
>
> --
> perl -le 'use Inline C=>q{SV*JAxH(char*x){return newSVpvf
> ("Just Another %s Hacker",x);}};print JAxH+Perl'
>
>
> Sent via Deja.com
> http://www.deja.com/




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

Date: Fri, 19 Jan 2001 03:37:27 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Child processes don't clean up (defunct processes left) even though SIGCHLD does wait()
Message-Id: <t6fdjnl2g4vu5c@corp.supernews.com>

Villy Kruse <vek@pharmnl.ohout.pharmapartners.nl> wrote:
> On Wed, 17 Jan 2001 16:31:11 -0000,
>           Geoff Winkless <geoff-at-farmline-dot-com@127.0.0.1> wrote:

If some of the variables in the below code seem silly because they don't
really vary, realize they are for demonstratio purposes.

[snip]

>>The question is, why would a child die but not pass a sigchld to its parent?

[snip]

> It can happen that two children terminates at the same time, but as
> sitnals are not queued the parent only sees one SIGCHLD.  Then you will
> see that the first child leaves no zombie but the second does.


> If you send the parent process a SIGCHLD using the kill command and 
> the one of the zombies goes away, then this is the explanation.

Good advice.

> To fix it, use waitpid(-1,&WNOHANG) in a loop until no pid is returned.

More good advice. If you happen to be somewhere broken enough to not offer
waitpid(), or (weird) offer it without the &WNOHANG option, you could go into
a wait() loop inside your SIGCHLD handler. This has the disadvantage of not
doing anything in the parent program until a child exits. This is, interestingly
enough, the same drawback as the code I offer below.

> Note, that some ancient unix systems doesn't support waitpid, but those
> are real ancient anyway.

Even if they don't, Perl lets you wait for a particular pid with flags of
0. You can build an array of child pids as you fork your children. This
way, you're still pretty portable. Unfortunately, you parent can't really
do much between forking and waiting this way, and you may wait out of
order ( and probably will if your children are very complex ).


If your parent manages your children and does little or nothing else, you
can do what I sometimes do. Fork off the children you need to fork, push
their pids onto an array, make a scalar the value of the number of
children you have, then go into a loop just wait()ing and decrementing
the number of children you have until you have no children. It can look
like this, although things are a little different if you need to
adjust the number of children while the parent is running:



############################################
my @kid_pid = ();
my $num_to_spawn = 5;
my $num_kids = 0;
my $im_the_parent = 1;
for(my $i = 0; $i < $num_to_spawn; $i++ ) {
    if( my $p = fork() ) {
        push(@kid_pid, $p);
        $num_kids = @kid_pid;
    } else {
        $im_the_parent = 0;
        last;
    }
}

unless( $im_the_parent ) {
    # child processing here
    exit;
}

while( $num_kids ) {
    my $dead_kid = wait;
    $num_kids--;
}
############################################



The above keeps you from relying on SIGCHLD explicity and from going into
a non-blocking loop ( even from needing a non-blocking option ). I should
note that the above is untested as-is. It is similar to some of my tested,
working code. If you never need to refer to your children, you don't even
have to keep the array of pids, as you could increment $num_kids instead.

Like I said though, if you need to adjust how many children are started,
such as re-forking children that have been reaped, this is too inflexible.

The code below uses the same ideas to keep a steady pool of kids, without
any outside stimulus telling you how many you should have. This code is
cut-and-pasted and is tested.

All code below this point is tested.



#############################################
#!/usr/bin/perl -w
use strict;

my $kiddie_pool = 3;
my $num_kids = 0;
my $im_the_parent = 1;

$SIG{TERM} = sub { $kiddie_pool = 0; };

sub spawn_kids($) {
    my $num_to_spawn = shift;
    return unless $num_to_spawn > 0;
    for(my $i = 0; $i < $num_to_spawn; $i++ ) {
        if( my $p = fork() ) {
            $num_kids++;
        } else {
            &be_a_kid;
            last;
        }
    }
}

sub be_a_kid {
    # child processing here
    exit;
}

&spawn_kids($kiddie_pool);

while( $num_kids ) {
    my $dead_kid = wait;
    print "$dead_kid\t$num_kids\n";
    $num_kids--;
    &spawn_kids($kiddie_pool - $num_kids);
}
#############################################



Granted, not determining how many children you need from the outside world
may still not be extremely flexible. You may have a few processes that hang
around a short time after exiting while you spawn more children, too. This
method, as coded, allows you to respawn children to keep a certain number
around and to still terminate somewhat gracefully. A SIGTERM handler
local to the child process ( within be_a_kid ) could help on terminating
gracefully, too.

See the Ram ( _Perl_Cookbook_ ) for examples of adjusting child pool size
based on outside information, such as network connections to a port.

There are ways to reap using Perl waitpid() without waitpid() being
implemented on the system, such as keeping around an array of your child
pids and looping through it with a blocking waitpid() for each child pid.
This spends a lot of time in the reaper sub, so you still have a practically
useless parent. You can, however, do some noncritical processing in the main
loop below without worry. Unlike the above examples, of course, the signal
handler in this one will break you away form the main loop if needed and
then drop you back into it. Since you spend so much time in the handler
( which, BTW, some will say is a bad idea ), though, you don't have much
time to spend in that loop. 


#################################################
#!/usr/bin/perl -w
use strict;

my $kiddie_pool = 3;
my $im_the_parent = 1;
my $still_going = 1;
my @kid_pid = ();

$SIG{TERM} = sub { $still_going = 0; };
$SIG{CHLD} = \&reaper;

sub spawn_kids($) {
    my $num_to_spawn = shift;
    return unless $num_to_spawn > 0;
    for(my $i = 0; $i < $num_to_spawn; $i++ ) {
        if( my $p = fork() ) {
            push(@kid_pid, $p);
        } else {
            &be_a_kid;
            last;
        }
    }
}

sub reaper() {
    $SIG{CHLD} = \&reaper;
    foreach( @kid_pid ) {
        my $result = waitpid($_, 0);
        if( $result > 0 ) {
            print "$_\t$kiddie_pool\n";
            &spawn_kids(1);
        }
    }
}

sub be_a_kid {
    # child processing here
    sleep( 2 );
    exit;
}

&spawn_kids($kiddie_pool);

while( $still_going ) {

}
#################################################


It's still a very good idea to consult the Ram.

Chris

-- 
Christopher E. Stith

Product shown enlarged to make you think you're getting more.



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

Date: Thu, 18 Jan 2001 23:49:11 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: excel to csv tools
Message-Id: <v50f6tcf3r875mp24uqa1kj2cj9ls6q6qk@4ax.com>

rbfitzpa@my-deja.com wrote:

>I found win32::ole and I think it will do exactly what I want.
>Unfortunatley I'm having a hard time installing it, it complains about a
>missing delimiter in the makefile when I try to install it. ( I checked
>and it's not installed on my system).

>I'm running on a solaris 2.6 machine, can I get a binary copy
>of win32::ole anywhere?

Whoops. I think this one is Win32 only. Hence the name. BTW do you even
have Excel for Solaris? YOu'd need that too, because this module only
serves to *control* Excel. Not replace it.

Have a look at the other suggestion: Spreadsheet::ParseExcel. THis one
works on its own, I would think.

-- 
	Bart.


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

Date: Thu, 18 Jan 2001 18:23:52 -0800
From: Kira <callgirl@la.znet.com>
Subject: Re: FAQ 9.15:   How do I decode a CGI form?
Message-Id: <3A67A538.F9D4BE6C@la.znet.com>

PerlFAQ Server wrote:

>   How do I decode a CGI form?
 
>     You use a standard module, probably CGI.pm. Under no circumstances
>     should you attempt to do so by hand!
 
>     You'll see a lot of CGI programs that blindly read from STDIN the number
>     of bytes equal to CONTENT_LENGTH for POSTs, or grab QUERY_STRING for
>     decoding GETs. These programs are very poorly written. They only work
>     sometimes. 

(snipped)

Total pile of Mule Manure. Posting this type of garbage
is an affront to all decent programmers.

Writing your own read and parse routine for handling
form action input data is infinitely superior to
this cgi.poopmaker, which is a well documented source
of problems and has a history of continuous upgrades
to compensate for these endless problems.

A home-grown Brenner style read and parse can be
accomplished, including superior security protection,
in less than one kilobyte compared to cgi.poopmaker's
over half-megabyte file size. Writing your own routine
to handle form actions helps to create faster, more
efficient and less memory intensive programs. Writing
your own routine leads to better learning, better
understanding of Perl and in-depth understanding of
what your program can do and, not do. Custom read
and parse routines allow for razzle dazzle tricks
and handling of conditions, parameters and special
needs, all of which most often cause cgi.poopmaker
to crap its britches.

Only catch with writing your own routine, you
have to know how to program quite well.

Use of cgi.poopmaker requires little more than
knowledge of how to use a mouse for copy and 
paste operations; rote textbook regurgitation.

Use of cgi.poopmaker for any program other than
simple mundane unimaginative programs, is assurance
of endless headaches and, assurance of significantly
boring programs. Its only worth, which is dubious,
is for commercial low quality production use.

I am significantly challenged to understand why
this Perl FAQ Server would post such baloney.
This FAQ is a disservice to our Perl Programming
Community and a display of programming ignorance
along with discouraging people to learn Perl.

Use of CGI.pm has its merits, use of hand written
read and parse routines has equal merits. To promote
only one, CGI.pm in this case, and to completely
discount the other, is evidence this FAQ Server 
is staffed and written by those who do not know
diddly-squat about true Perl Programming; they
are Cargo Cultists giving bad advice.



Godzilla!
-- 
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class


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

Date: 19 Jan 2001 03:49:40 GMT
From: damian@puma.qimr.edu.au (Damian James)
Subject: Re: FAQ 9.15:   How do I decode a CGI form?
Message-Id: <slrn96fec1.a2r.damian@puma.qimr.edu.au>

Thus spake Kira on Thu, 18 Jan 2001 18:23:52 -0800:
>
>Use of CGI.pm has its merits, use of hand written
>read and parse routines has equal merits. To promote
>only one, CGI.pm in this case, and to completely
>discount the other, is evidence this FAQ Server 
>is staffed and written by... Cargo Cultists giving 
>bad advice.
>

Having recently inherited and been required to support 30 odd thousand 
lines of code written by someone who thought that implementing their own 
cgi parser was a good way to learn Perl, I can only recoil in horror from 
the sentiments expressed above. 

My only option was to do a complete rewrite of the system. This took
months, and I still had to periodically track down ridiculous bugs in the
old system (which was 50% HTML, since my predecessor hadn't heard of
HTML::Template or Text::Template either).

If you want to re-cover old ground, you should be writing your own memory
management, IO routines and device drivers as well. And a compiler for that
matter. None of these are suitable projects for beginners.

Most people asking FAQs are beginners (otherwise they wouldn't be asking),
and it's quite appropriate that the answers should be tailored to suit. 

You are suggesting that if somebody asks "How do I make my car go forward?", 
the correct answer is not "Push the gas pedal", but "Open the hood, attach a
piece of string to the lever on the fuel valve (ignore or detach the cable
that's already attached to it), run the string inside through the firewall 
to the driver's seat. Close the hood, start the engine, put the car in Drive. 
Now pull on the string. Note that this might not work as expected if you have
a fuel-injected engine."

This should foreground what the real problem is: a complete beginner
might not be able to tell which is better advice.

HTH

Cheers,
Damian


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

Date: Thu, 18 Jan 2001 20:47:15 -0800
From: Kira <callgirl@la.znet.com>
Subject: Re: FAQ 9.15:   How do I decode a CGI form?
Message-Id: <3A67C6D3.E2639226@la.znet.com>

Damian James wrote:
 
> Thus spake Kira on Thu, 18 Jan 2001 18:23:52 -0800:


(my comments have been snipped and not noted by Mr. James)


> >Use of CGI.pm has its merits, use of hand written
> >read and parse routines has equal merits. To promote
> >only one, CGI.pm in this case, and to completely
> >discount the other, is evidence this FAQ Server
> >is staffed and written by... Cargo Cultists giving
> >bad advice.

 
> Having recently inherited and been required to support 30 odd thousand
> lines of code written by someone who thought that implementing their own
> cgi parser was a good way to learn Perl, I can only recoil in horror from
> the sentiments expressed above.

(snipped)
 

Your comments are both single incident specific
and contexually unrelated to my previous comments
thus irrelevant.


Godzilla!


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

Date: Fri, 19 Jan 2001 03:31:48 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Flock flaky over NFS how about fcntl?
Message-Id: <3A67B90E.F0A9918E@home.com>

[posted & mailed]

chuckk@monmouth.com wrote:
> 
> I posted a message a while back about flock being flaky over NFS

Didn't see it and am not about to go looking for it.

> when multiple programs on multiple machines try to flock the same file
> on a NFS mounted device.

Yes, this is mentioned in the FAQ.

> ***I forgot to ask an obvious question....***
> 
> Does fcntl suffer from the same problem?

The FAQ suggests that it might.  `man 2 fcntl` on your system should
give a more definite answer.

> Any people have experience trying this?

Trying what?

-- 
Rick Delaney
rick.delaney@home.com


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

Date: 19 Jan 2001 00:01:14 -0500
From: jdf@pobox.com
Subject: Hello.  I'm back.
Message-Id: <lms8dtk5.fsf@pobox.com>

Hello.  My name is Jonathan Feinberg.  I used to be a frequent poster
to this group and to c.l.p.moderated.  I gave up in exhaustion some
time ago--perhaps a year or so--but I'm back.  I've begun teaching a
Perl class at a local corporate technical cubical farm, and I'm having
a good time, so I thought I'd share the love.

Sadly, I've lost my old killfile.  Any of you old-timers have a
gnus-compatible scorefile for c.l.p.m that you'd care to email to me?
I think you know what I'm talking about.

Hello Randal, hello rootbeer, hello Larry Rosler, hello Andrew
Langmead, and are you out there gellyfish?  Hello MJD, hello brian d
foy, no point saying hello to tchrist, and hello to everyone in
general.
-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf


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

Date: Fri, 19 Jan 2001 03:52:50 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: HELP: httpS protocol (https and NOT http)!
Message-Id: <3A67BDFC.845D9D74@home.com>

[posted & mailed]

Federico Bari wrote:
> 
>     I have a lot of problem to find out informations and above all example
> of how to install and use HTTPS (secure http) protocol module. Using the
> standard http I get an error answer something as "404 https protocol not
                                      ^^^^^^^^^^^^
"Something as" is not as good as posting the actual error.


> allowed". I have given a look to te documents at www.perl.com but there are
> too few information. If somebody PLEASE could give me an example; here above
> some lines of code. How have I to modify them?
> 
>  use LWP::UserAgent;

You shouldn't have to modify anything if you have Crypt::SSLeay
installed.  There is a whole manpage on how to install modules.

perldoc perlmodinstall

Also, look at the HTTPS section of

perldoc lwpcook

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Thu, 18 Jan 2001 18:17:29 -0600
From: "Scott F" <sdf@expertune.com>
Subject: How do I page output in the debugger on Win32?
Message-Id: <3a678790$0$7163$272ea4a1@news.execpc.com>

The perldebug manpage says,

    |dbcmd      Run the debugger command, piping DB::OUT into your current
pager.

Maybe on Unix, but not on Windows 2000, ActiveState Perl 5.6.0 build 623.

Is there a way to do this on Windows, i.e., without making a worse problem
than it solves?

Scott F

Muse: Pity, the people on clpm most qualified to answer this don't use
Win32.






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

Date: Thu, 18 Jan 2001 23:33:18 GMT
From: hmug@my-deja.com
Subject: Re: How to Create a Perl Shared Library (.so file) ?
Message-Id: <947ufu$4e0$1@nnrp1.deja.com>

Hi Brian (and every guru out there),

The the thing is, I want to create a shared library (in C) that I can
call from PL/SQL. My problem now is creating the shared library.

How can I create a shared library from the C code that has embedded
perl (on Linux Redhat 6.1).

When I call the shared library routine in pl/sql I get some symbol
referencing error to do with the fact that the perlembed api functions
are not defined. I tried to create the shared library by including -L
path options to the perlembed libraries (by the way).


Can I create the shared library with the Inline module? If so how?
Thanks.

Your help is highly appreciated.

Henry


In article <946j76$rs0$1@nnrp1.deja.com>,
  Brian Ingerson <briani@activestate.com> wrote:
> In article <944qui$cop$1@nnrp1.deja.com>,
>   hmug@my-deja.com wrote:
> > Hi Anno,
> >
> > Many Thanks!! I was nearly running mad!
> >
> > Might you know how I can embed perl in C? Or do you have any nice
> > pointers?
>
> If you are familiar with Inline.pm as a way to extend Perl with C,
> Inline::CPR is a very simple way to embed Perl in C. You just put a
> hashbang line:
>
> #!/usr/bin/cpr
>
> at the top of your C source file, and then run the source. Really! As
an
> added bonus you'll have automatic access to the PerlAPI. You don't
have
> to start a perl interpreter, because your entire C program is already
> running _under_ a perl interpreter.
>
> The module's not as robust as Inline yet, but it's quite easy and a
bit
> of fun too.
>
> Brian
>
> --
> perl -le 'use Inline C=>q{SV*JAxH(char*x){return newSVpvf
> ("Just Another %s Hacker",x);}};print JAxH+Perl'
>
> Sent via Deja.com
> http://www.deja.com/
>


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 19 Jan 2001 02:55:09 GMT
From: Lee.Lindley@bigfoot.com
Subject: Re: How to Create a Perl Shared Library (.so file) ?
Message-Id: <948aaa$edh$1@nnrp1.deja.com>

In article <947ufu$4e0$1@nnrp1.deja.com>,
  hmug@my-deja.com wrote:
> Hi Brian (and every guru out there),
>
> The the thing is, I want to create a shared library (in C) that I can
> call from PL/SQL. My problem now is creating the shared library.
>
> How can I create a shared library from the C code that has embedded
> perl (on Linux Redhat 6.1).
>

This is what I do.  If there is a better way, I welcome suggestions.

1) Configure and build a static version of perl and install
it for efficiency.
2) Copy the bin/perl executable to bin/perl.static
3) Configure and build a shared library version of perl and
install it.  Now your Config.pm module and such think that
you have a libperl.so and the ExtUtils modules can help
you with making other libraries and exectuables.
4) Copy bin/perl to bin/perl.shared
5) Link or copy bin/perl.static to bin/perl.  This gives
you the speed advantage of the statically built perl
application for most common usage.
6) Rename lib/libperl.a to lib/libperl.a.static (or some such).
I don't know that this is required, but I only wated the
libperl.so file to be in the lib path that is searched.

Per the perlembed documentation, you create a Makefile that
looks something like this where $(PERL) is the full path
to your perl executable:

perlxsi.o:  perlxsi.c
    gcc $(CFLAGS) -o perlxsi.o -c perlxsi.c\
      `$(PERL) -MExtUtils::Embed -e ccopts`

perlxsi.c:   $(PERL)
    $(PERL) -MExtUtils::Embed -e xsinit -- -o $@

yourembedder.o:  yourembedder.c yourembedder.h $(PERL)
    gcc $(CFLAGS) $(INCFLAGS) -o $@ -c yourembedder.c \
      `$(PERL) -MExtUtils::Embed -e ccopts`

lib:    $(OBJS) # includes yourembedder.o and xsinit.o
    rm -f libyourlib*
    gcc $(CFLAGS) -fPIC -G -o libyourlib.so.1.0 $(OBJS)\
    `$(PERL) -MExtUtils::Embed -e ldopts`
    ln -s libyourlib.so.1.0 libyourlib.so

#
then make lib and make install (assuming you created
an install target)

Obviously, I've left out some of the variable settings, but
hopefully between this and the documentation you will figure
out how to resolve everything.

The key thing you may be missing is libperl.so. If you built
your perl static (which is the recommended and default way),
then you are stuck until you build a libperl.so.  By my
thinking, the answers you get back from ExtUtils::Embed
will not be helpful unless you actually install that perl
too.  But I made a number of assumptions to arrive
at that conclusion and am not intimately familiar with
the perl build process (though it seems like I've spent
ages doing it :-).  There may be a better way.

Corrections welcome.


--
// Lee.Lindley@Bigfoot.com


Sent via Deja.com
http://www.deja.com/


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

Date: 18 Jan 2001 16:39:16 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: how to match a space character
Message-Id: <m3ofx4mqnf.fsf@dhcp11-177.support.tivoli.com>

vupt@yahoo.com writes:

> Just a quick easy question that is driving me nuts. How do I match a
> blank space?

  / /;  # will match a space character
  /\s/; # will match any white-space character (space, tab, etc.)

> For example if $string="hhh hhh";
> I want the below snippet to pring "hhhhhh" {I want blank to be omitted}

Now that is something different entirely.  You either want to print
all of the non-blank characters, or you want to remove the blanks from
the string.

For the latter:

  $string =~ tr/ //d;  # if other white-space, use s/\s+//g;

> But everytime I run the code, "hhh hhh" is printed which suggests to me
> that the blank space is being matched when I don't want it to.
> 
> foreach($string){
>    if($_ ne " " ){
>      print "$_";
>     }
> }

This code looks as if you expect $string to be an array of its
characters, which it isn't in Perl.  If you *really* want this type of
behavior -- that is, don't modify the string, or even a copy of the
string, just print the non-space characters, then you could use
something like:

  print for grep !/ /, split //, $string;

But you don't really want to do that... :)

-- 
Ren Maddox
ren@tivoli.com


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

Date: 18 Jan 2001 18:09:41 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: how to match a space character
Message-Id: <m37l3smmgq.fsf@dhcp11-177.support.tivoli.com>

vupt@yahoo.com writes:

> My original goal was that I needed to determine if a string was made up
> of blanks or not. For example
> "aaaaa" not empty, "   " empty.

  print "Only blanks!" if $string =~ /^ +$/;

Which assumes that an empty string does not qualify as it doesn't have
any blanks.  If you want to count an empty string as a string of only
blanks, you could change the "+" to a "*", or you could use the more
efficient:

  print "Only blanks!" unless $string =~ /[^ ]/;

which just tries to find a single non-blank character in the string.

> Here is a function that I wrote that seems to do what I want. I'm sure
> there must be a better way to determine if a string is made up of
> blanks. But here is a function that I came up with that seems to do
> what I want.
> sub isEmptyString{
>   ($string)=@_;
>   $_ = $string;

You aren't using $string for anything here.  You could just use:

    ($_) = @_;

or, as I would prefer:

    local $_ = shift;

>   $length = tr/a-zA-Z/0-9/;

Not sure exactly what you think this does, but what it actually does
is replace all the letters in the string with numbers (mostly 9s) and
sets length to the number of such letters so changed.  This does have
the effect of returning a positive number for any string that has
(had) letters in it.  But try it with a string that only has numerals
and see what you get.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 18 Jan 2001 23:30:04 -0000
From: Khuong H. Dinh <kdinh@commerce-tv.com>
Subject: How to search for a certain entity's value in a xml file
Message-Id: <t6ev3snduv5qbf@corp.supernews.com>

Hi,

I'm pretty new with perl.  I'm trying to find a way to search through an 
xml file and get out of that value of some entities.  For example I have 
an xml file:

 <?xml version="1.0" encoding="UTF-8" ?> 
- <table>
  <name1>234</name1> 
  <versionNumber>1.0</versionNumber> 
  <errorName>0</errorName> 
  </table>

Is there a way that I can get out value of entity name1?
I would appreciate any helps.

Thanks.


--
Posted via CNET Help.com
http://www.help.com/


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

Date: Fri, 19 Jan 2001 02:22:45 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: How to search for a certain entity's value in a xml file
Message-Id: <VxN96.414$032.15032@eagle.america.net>

On Thu, 18 Jan 2001 23:30:04 -0000, Khuong H. Dinh
<kdinh@commerce-tv.com> wrote:
>I'm pretty new with perl.  I'm trying to find a way to search through an 
>xml file and get out of that value of some entities.  For example I have 
>an xml file:
>
> <?xml version="1.0" encoding="UTF-8" ?> 
>- <table>
 ^
 ^ Oops.  This is a syntax error.  

>  <name1>234</name1> 
>  <versionNumber>1.0</versionNumber> 
>  <errorName>0</errorName> 
>  </table>
>
>Is there a way that I can get out value of entity name1?
>I would appreciate any helps.

Yes.  Take a look at XML::Parser.  

-- 
Garry Williams


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

Date: Thu, 18 Jan 2001 23:28:33 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: lookbehind in s///g
Message-Id: <7lue6tgb1rq25b92s8hhbhhtgtgol5k23l@4ax.com>

Lookbehind doesn't seem to work as I'd expect it to work, in s///g. For
example:

	$_ = 'aaabbbaabaabaaababbaaabab';
	s/(?<=a)(a)|(a)/$1?'Y':'X'/ge;
	print;

Any "a" precdeded by an "a", will be replaced by "Y". All others, the
first "a"'s so to speak, will be replace by "X". This prints:

	XYYbbbXYbXYbXYYbXbbXYYbXb


Before you claim that this is normal, think about it: as each "a" is
either replaced by "X" or "Y", there no longer is an "a" to precede any
following "a". So there shoudln't be any "Y" at all!

In short: lookbehind looks at the string before the substitution, not
the string that results from the previous substitution.

By comparison: a similar problem occurs when you test length of $` in
each substitution. You'll see the old length, not the substituted one.
This problem, which BTW is old hat, crops up when trying to replace tabs
with spaces, in order to determine the next tabstop.

-- 
	Bart.


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

Date: 19 Jan 2001 00:09:30 GMT
From: abigail@foad.org (Abigail)
Subject: Re: lookbehind in s///g
Message-Id: <slrn96f1dq.8jg.abigail@tsathoggua.rlyeh.net>

Bart Lateur (bart.lateur@skynet.be) wrote on MMDCXCVII September MCMXCIII
in <URL:news:7lue6tgb1rq25b92s8hhbhhtgtgol5k23l@4ax.com>:
%% Lookbehind doesn't seem to work as I'd expect it to work, in s///g. For
%% example:
%% 
%% 	$_ = 'aaabbbaabaabaaababbaaabab';
%% 	s/(?<=a)(a)|(a)/$1?'Y':'X'/ge;
%% 	print;
%% 
%% Any "a" precdeded by an "a", will be replaced by "Y". All others, the
%% first "a"'s so to speak, will be replace by "X". This prints:
%% 
%% 	XYYbbbXYbXYbXYYbXbbXYYbXb
%% 
%% 
%% Before you claim that this is normal, think about it: as each "a" is
%% either replaced by "X" or "Y", there no longer is an "a" to precede any
%% following "a". So there shoudln't be any "Y" at all!

That can easily be done with:

    1 while s/(?<=a)(1)|(a)/$1?'Y':'X'/e;

%% In short: lookbehind looks at the string before the substitution, not
%% the string that results from the previous substitution.

By the same logic:

    $_ = 'aa';
    s/a/aa/g;

should never terminate, and

    $_ = 'aaaaaa';
    s/aaa/baa/g;

should produce

    bbbbaa

instead of

    baabaa

%% By comparison: a similar problem occurs when you test length of $` in
%% each substitution. You'll see the old length, not the substituted one.

Since $` is the part of the string before the match, and since s///
replaces what matches, how could $` change, let alone its length change?



Abigail
-- 
print 74.117.115.116.32.97.110.111.116.104.101.114.
      32.80.101.114.108.32.72.97.99.107.101.114.10;


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

Date: 18 Jan 2001 18:19:49 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: lookbehind in s///g
Message-Id: <m33degmlzu.fsf@dhcp11-177.support.tivoli.com>

Bart Lateur <bart.lateur@skynet.be> writes:

> Lookbehind doesn't seem to work as I'd expect it to work, in s///g. For
> example:
> 
> 	$_ = 'aaabbbaabaabaaababbaaabab';
> 	s/(?<=a)(a)|(a)/$1?'Y':'X'/ge;
> 	print;
> 
> Any "a" precdeded by an "a", will be replaced by "Y". All others, the
> first "a"'s so to speak, will be replace by "X". This prints:
> 
> 	XYYbbbXYbXYbXYYbXbbXYYbXb

Notably, switching from ".../g" to "1 while ..." gives the "expected"
result:

        XXXbbbXXbXXbXXXbXbbXXXbXb

> Before you claim that this is normal, think about it: as each "a" is
> either replaced by "X" or "Y", there no longer is an "a" to precede any
> following "a". So there shoudln't be any "Y" at all!
> 
> In short: lookbehind looks at the string before the substitution, not
> the string that results from the previous substitution.

I assume this is because a global substitution never backtracks past
the point of the previous success, and it already "matched" the first
"a" and doesn't look again.

> By comparison: a similar problem occurs when you test length of $` in
> each substitution. You'll see the old length, not the substituted one.
> This problem, which BTW is old hat, crops up when trying to replace tabs
> with spaces, in order to determine the next tabstop.

Interesting that the "fix" for both of these is the "1 while"
thing.... :)

-- 
Ren Maddox
ren@tivoli.com


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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


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