[30531] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1774 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 6 14:14:22 2008

Date: Wed, 6 Aug 2008 11:14:14 -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, 6 Aug 2008     Volume: 11 Number: 1774

Today's topics:
        Need help with perlxs and C strings <th@example.invalid>
    Re: Need help with perlxs and C strings <smallpond@juno.com>
    Re: Need help with perlxs and C strings <fawaka@gmail.com>
    Re: Need help with perlxs and C strings xhoster@gmail.com
    Re: nested strings <tzz@lifelogs.com>
    Re: Newbie: Simple conditional on regexp match <kenneth.brun.nielsen@googlemail.com>
    Re: Newbie: Simple conditional on regexp match xhoster@gmail.com
        Perl distributed as one all-inclusive Windows binary? yojrod@gmail.com
    Re: PPM - scripting <slick.users@gmail.com>
    Re: PPM - scripting <ben@morrow.me.uk>
        tool/idea to "opimize" code / remove unused methods <ghaslbe@gmx.de>
    Re: tool/idea to "opimize" code / remove unused methods <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 06 Aug 2008 15:12:24 +0200
From: Thomas <th@example.invalid>
Subject: Need help with perlxs and C strings
Message-Id: <g7c7vp$6cp$1@aioe.org>

I've spent several hours now reading documentation, a tutorial and a 
magazine article on perlxs and I can't get a minimal example to run. 
What I want to accomplish:

* Write some data into a C char array in C code, e.g. like this:
void set_data(char * s)
{
	s[0] = 'a';
	s[1] = 'b';
}

* Call that C function from a Perl module and use the String from within 
  a Perl program. For the moment, just print it to stdout.

Can anyone provide me with a small running example which I can extend? 
At http://search.cpan.org/~rgarcia/perl-5.10.0/pod/perlxs.pod there are 
many pages of documentation but no concise instructions on what to do. 
Other tutorials start with a call to h2xs and pages of modifications to 
be made just for me to learn that the whole thing doesn't work (example: 
  "change line with X to Y", only there is no line X). I'd like to use a 
small working example if you know of such a thing. If not, maybe someone 
can write it up, it shouldn't be more than a couple of lines?!

Part of my problem is that I don't know which tools to use on which 
files in what order. Documentation is lengthy, but that basic 
information seems to be missing. All solutions seem to work with lengthy 
Makefile constructs which I'd like to avoid for the time being.

Thanks in advance, any help very much appreciated.


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

Date: Wed, 6 Aug 2008 07:29:30 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: Need help with perlxs and C strings
Message-Id: <457527e9-5819-4905-b7d0-21d97a176a01@25g2000hsx.googlegroups.com>

On Aug 6, 9:12 am, Thomas <t...@example.invalid> wrote:
> I've spent several hours now reading documentation, a tutorial and a
> magazine article on perlxs and I can't get a minimal example to run.
> What I want to accomplish:
>
> * Write some data into a C char array in C code, e.g. like this:
> void set_data(char * s)
> {
>         s[0] = 'a';
>         s[1] = 'b';
>
> }
>
> * Call that C function from a Perl module and use the String from within
>   a Perl program. For the moment, just print it to stdout.
>
> Can anyone provide me with a small running example which I can extend?
> Athttp://search.cpan.org/~rgarcia/perl-5.10.0/pod/perlxs.podthere are
> many pages of documentation but no concise instructions on what to do.
> Other tutorials start with a call to h2xs and pages of modifications to
> be made just for me to learn that the whole thing doesn't work (example:
>   "change line with X to Y", only there is no line X). I'd like to use a
> small working example if you know of such a thing. If not, maybe someone
> can write it up, it shouldn't be more than a couple of lines?!
>
> Part of my problem is that I don't know which tools to use on which
> files in what order. Documentation is lengthy, but that basic
> information seems to be missing. All solutions seem to work with lengthy
> Makefile constructs which I'd like to avoid for the time being.
>
> Thanks in advance, any help very much appreciated.

Your array is not a legal C string (not null-terminated), and also not
a legal perl scalar type, which is called SV in perlguts.  You would
use sv_setpvn to convert a C char array into a perl scalar.

There are plenty of CPAN modules that are partly written in C.  Cwd is
one example that handles strings.

--S


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

Date: 06 Aug 2008 15:39:08 GMT
From: Leon Timmermans <fawaka@gmail.com>
Subject: Re: Need help with perlxs and C strings
Message-Id: <4899c59c$0$49896$e4fe514c@news.xs4all.nl>

On Wed, 06 Aug 2008 15:12:24 +0200, Thomas wrote:

> Part of my problem is that I don't know which tools to use on which
> files in what order. Documentation is lengthy, but that basic
> information seems to be missing. 
>

I think you will want to read perlguts (and maybe some of perlapi) before 
trying to do that. They cover the basics.

Regards,

Leon Timmermans


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

Date: 06 Aug 2008 16:23:15 GMT
From: xhoster@gmail.com
Subject: Re: Need help with perlxs and C strings
Message-Id: <20080806122316.745$1G@newsreader.com>

Thomas <th@example.invalid> wrote:
> I've spent several hours now reading documentation, a tutorial and a
> magazine article on perlxs and I can't get a minimal example to run.

Writing directly in XS is hard. Try Inline::C for something easier.

> What I want to accomplish:
>
> * Write some data into a C char array in C code, e.g. like this:
> void set_data(char * s)
> {
>         s[0] = 'a';
>         s[1] = 'b';
> }
>
> * Call that C function from a Perl module and use the String from within
>   a Perl program. For the moment, just print it to stdout.

use strict;
use warnings;
use Inline 'C' ;
my $x="xxxxxxx";
print "$x\n";
set_data($x);
print "$x\n";
__DATA__
__C__
void set_data(char * s)
{
        s[0] = 'a';
        s[1] = 'b';
}

output:
xxxxxx
abxxxx


It is easy to get segfaults and other bad things using this method, if
you aren't careful.  For example, the SV passed in ($x, here) better have
storage already allocated for those two bytes, and already think the string
is at least 2 bytes long.


> Can anyone provide me with a small running example which I can extend?

See above.  Also, you can tell Inline not to clean up the build directory
(CLEAN_AFTER_BUILD => 0), so you can also go searching through the _Inline
build directory to see what the xs that Inline makes on your behalf looks
like.


> At http://search.cpan.org/~rgarcia/perl-5.10.0/pod/perlxs.pod there are
> many pages of documentation but no concise instructions on what to do.

The "what to do" is implicit.  It is documentation.  It is there to be
read. read it, if you want to understand what XS.  If you want to flail
around using the trial and error, then the docs is not what you want.


> Other tutorials start with a call to h2xs and pages of modifications to
> be made just for me to learn that the whole thing doesn't work (example:
>   "change line with X to Y", only there is no line X).

Before discovering the terrifying simplicity of Inline::C, I followed the
examples given in, ah, some tutorial or another that involved h2xs.  It
worked to get me a working example.  If it didn't work for you, what can I
say?  You haven't given us enough details.  If the docs are wrong, we might
be able to fix them, but not if you hide the errors behind "X" and "Y".

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Wed, 06 Aug 2008 11:23:09 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: nested strings
Message-Id: <86ej52jeoi.fsf@lifelogs.com>

On Tue, 5 Aug 2008 14:51:27 -0700 (PDT) sausenet@gmail.com wrote: 

s> Given: a list of words sorted first in length order, then
s> alphabetically:
s>     FORMATION
s>     FORMATIVE
s>     FORMATTER
s>     DEFORMATION
s>     DEFORMATIVE
s>     FORMATIVELY
s>     INFORMATICS
s>     INFORMATION
s>     INFORMATIVE
s>     INFORMATORY
s>     CONFORMATION
s>     MALFORMATION
s>     DEFORMATIONAL
s>     INFORMATIONAL
s>     INFORMATIVELY
s>     UNINFORMATIVE

s> Desired output: the same set of words showing nested substrings
s>     FORMATION [DEFORMATION [DEFORMATIONAL] INFORMATION [INFORMATIONAL]
s> CONFORMATION MALFORMATION]
s>     FORMATIVE [DEFORMATIVE FORMATIVELY [INFORMATIVELY] INFORMATIVE
s> PERFORMATIVE UNINFORMATIVE]
s>     FORMATTER
s>     INFORMATICS
s>     INFORMATORY

You probably want a trie.

http://en.wikipedia.org/wiki/Trie

http://search.cpan.org/~avif/Tree-Trie-1.5/Trie.pm

Ted


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

Date: Wed, 6 Aug 2008 06:08:33 -0700 (PDT)
From: Kenneth Brun Nielsen <kenneth.brun.nielsen@googlemail.com>
Subject: Re: Newbie: Simple conditional on regexp match
Message-Id: <e2837d71-6684-4794-83e8-9aaabfb955c1@z72g2000hsb.googlegroups.com>

On Aug 6, 11:54=A0am, Kenneth Brun Nielsen
<kenneth.brun.niel...@googlemail.com> wrote:
> I need to perform a conditional on a regexp match. How can I do that
> (easily) in PERL.
>
> The following prints out all lines - also the ones, that doesnt match
> the regular expression.
>
> #!/usr/bin/perl -w
> open FILEHANDLE, "soatest.soa";
> while (<FILEHANDLE>){
> =A0 =A0 if (/^\*| XI/) {
> =A0 =A0 =A0 =A0 print "match in line: $.\n";
> =A0 =A0 }
>
>
>
> }

DOH! I found out that the above works as intended. I just "forgot" to
escape the | in the regexp.


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

Date: 06 Aug 2008 16:27:06 GMT
From: xhoster@gmail.com
Subject: Re: Newbie: Simple conditional on regexp match
Message-Id: <20080806122707.898$38@newsreader.com>

Kenneth Brun Nielsen <kenneth.brun.nielsen@googlemail.com> wrote:
> I need to perform a conditional on a regexp match. How can I do that
> (easily) in PERL.
>
> The following prints out all lines - also the ones, that doesnt match
> the regular expression.

I don't believe you.  Show us an example of soatest.soa that demonstrates
this behavior.

>
> #!/usr/bin/perl -w
> open FILEHANDLE, "soatest.soa";
> while (<FILEHANDLE>){
>     if (/^\*| XI/) {
>         print "match in line: $.\n";
>     }
> }

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Wed, 6 Aug 2008 11:03:03 -0700 (PDT)
From: yojrod@gmail.com
Subject: Perl distributed as one all-inclusive Windows binary?
Message-Id: <8d2fc726-06b3-4af0-903d-cdb137b31f22@j33g2000pri.googlegroups.com>

Anyone know of a download or version of Perl for Windows that does not
rely on libraries? (i.e., you can run this exe on any Windows machine,
independent of required installations or libraries?)

Thanks for any help.


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

Date: Wed, 6 Aug 2008 09:12:45 -0700 (PDT)
From: Slickuser <slick.users@gmail.com>
Subject: Re: PPM - scripting
Message-Id: <70cb6f6b-5040-4d5a-b7fb-faaa54590e3c@v39g2000pro.googlegroups.com>

On Aug 5, 6:43 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> QuothSlickuser<slick.us...@gmail.com>:
>
> > Hey guys,
>
> > I would like to a create PPM that compile on Windows.
>
> I'm not sure what you mean by a 'PPM'. Are you referring to
> ActiveState's Perl Package Manager packages? If so, then you don't need
> to turn your script into a package before you turn it into an
> executable: the package would only be useful if you wanted to give it
> to someone else with a copy of ActiveState Perl already installed.

Yes, I am planning to distribute the executable code only. No Perl
source code and the client doesn't have Perl install.

>
> > I am planning to
> > buy Perl Dev Kit Pro which can turn my Perl script into executable.
>
> I suspect there won't be many people here who know much about Perl Dev
> Kit Pro, since it isn't freely available, but the PAR::Packer module on
> CPAN provides a pp command that makes it very easy to do just that.
>
> > Before that, I want to make sure if this could be achieve on Perl and
> > is there any example out there.
>
> > For example, it will look like this:
>
> > game.ppm
>
> OK, now I'm really confused. Surely you mean 'game.exe'?
>
> > So I want "game" command to be executable on Windows prompt.
>
> > > game start
> > > game display -name "Slickuser"
> > > game stop
> > > game exit
>
> > "game" will be overall script
> > "display" will be a sub function
> > "-name" will be the option follow by arguments
>
> That is certainly possible with pp, and I am sure it's possible with
> ActiveState's tool as well. Write a Perl script you can invoke like
>
>     perl game start
>     perl game display -name "Slickuser"

Is it possible to get rid of "perl"? Since the client will not have
Perl installed.
I will convert the .pl or .ppm to .exe format from Perl Pro Dev Kit.

>
> (see @ARGV in perlvar if you need help with that) and then package it up
> with your tool of choice.
>
> Ben
>
> --
> BEGIN{*(=sub{$,=*)=sub{print@_};local($#,$;,$/)=@_;for(keys%{ #...@morrow.me.uk
> $#}){/m/&&next;**=${$#}{$_};/(\w):/&&(&(($#.$_,$;.$+,$/),next);$/==\$*&&&)($;.$
> _)}};*_=sub{for(@_){$|=(!$|||$_||&)(q) )));&((q:\:\::,q,,,\$_);$_&&&)("\n")}}}_
> $J::u::s::t, $a::n::o::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $,



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

Date: Wed, 6 Aug 2008 18:18:10 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: PPM - scripting
Message-Id: <iv2pm5-bl2.ln1@osiris.mauzo.dyndns.org>


Quoth Slickuser <slick.users@gmail.com>:
> On Aug 5, 6:43 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> >
> > That is certainly possible with pp, and I am sure it's possible with
> > ActiveState's tool as well. Write a Perl script you can invoke like
> >
> >     perl game start
> >     perl game display -name "Slickuser"
> 
> Is it possible to get rid of "perl"? Since the client will not have
> Perl installed.
> I will convert the .pl or .ppm to .exe format from Perl Pro Dev Kit.

Yes, that was my point. *If* you start with a script that can be invoked

    perl game start

and then package it up into game.exe, game.exe should be invoked as

    game start

Ben

-- 
BEGIN{*(=sub{$,=*)=sub{print@_};local($#,$;,$/)=@_;for(keys%{ #ben@morrow.me.uk
$#}){/m/&&next;**=${$#}{$_};/(\w):/&&(&(($#.$_,$;.$+,$/),next);$/==\$*&&&)($;.$
_)}};*_=sub{for(@_){$|=(!$|||$_||&)(q) )));&((q:\:\::,q,,,\$_);$_&&&)("\n")}}}_
$J::u::s::t, $a::n::o::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $,


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

Date: Wed, 06 Aug 2008 19:26:17 +0200
From: Gerhard Haslberger <ghaslbe@gmx.de>
Subject: tool/idea to "opimize" code / remove unused methods
Message-Id: <g7cmrr$1q9$1@online.de>

Hi,

i have no idea for what i should look on google so maybe someone can 
give me hints or tips.

Is it possible to find unused variables / methods in a perlscript and 
all included scripts?
Any Ideas or tools?

thanx for any hint!


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

Date: Wed, 6 Aug 2008 18:49:37 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: tool/idea to "opimize" code / remove unused methods
Message-Id: <hq4pm5-ak4.ln1@osiris.mauzo.dyndns.org>


Quoth Gerhard Haslberger <ghaslbe@gmx.de>:
> Hi,
> 
> i have no idea for what i should look on google so maybe someone can 
> give me hints or tips.
> 
> Is it possible to find unused variables / methods in a perlscript and 
> all included scripts?
> Any Ideas or tools?

B::Xref might be helpful.

Ben

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


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

Date: 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 V11 Issue 1774
***************************************


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