XS help



  • 1. mass-replacing large block of text
    I have ~97 HTML documents that I need to strip the footer (about 15 lines) from and replace with a different block of text. The footer is formatted differently in some of the HTML files, but they all start with the line: <table border="0" width="100%" height="5%"> How can I replace everything after that particular line with a custom block of text? Thanks. -- Andrew Gaffney
  • 2. Convert letter to phone keypad equivalent
    Hello everyone, Here's a script I wrote to convert letters into their telephone keypad equivalents....example....A-B to 2, D-F to 3, etc. #!/usr/bin/perl use warnings; use strict; my $cnum = 'SM1550'; $cnum =~ s/[A-C]/2/g; $cnum =~ s/[D-F]/3/g; $cnum =~ s/[G-I]/4/g; $cnum =~ s/[J-L]/5/g; $cnum =~ s/[M-O]/6/g; $cnum =~ s/[P-S]/7/g; $cnum =~ s/[T-V]/8/g; $cnum =~ s/[W-Y]/9/g; print "$cnum\n" This works like a charm, but I wondered if anyone knew of a way to consolidate this into fewer regex's. Like my post earlier this week, I'm not trying to be lazy, just trying to learn other ways of programming/consolidating regexes. Any help is appreciated, Kevin -- Kevin Old < XXXX@XXXXX.COM >

XS help

Postby rajnikant_jachak » Sat, 26 Jul 2008 19:35:35 GMT

Hello All,
I'm trying to call C routine from Perl using XS but some how my 'make test'
is failing. Following are the steps I did :
file: hypotenuse.h
      double hypotenuse(double x, double y); /* Func Declaration */
file: hypotenuse.c
      /* Func Definition */
     double hypotenuse(double x, double y)
           return sqrt(x*x + y*y);

Steps :
1.  h2xs -n Geometry -A -O -x -F '-I ../..' hypotenuse.h   /created XS
2. cd Geometry               // Went in the directory
3. cp ../hypotenuse.* .     // Copied header and source files in Dir
4. Added Geometry.o and hypotenuse.o as objects in Makefile.pl
5. Perl Makefile.pl  and make is ok
6. 'make test' is failing 
Do someone have any idea where I'm going wrong? I did not read perl doc for
XS yet :(.
Error logs:
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e"
"test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/Geometry....NOK 1
#   Failed test 'use Geometry;'
#   in t/Geometry.t at line 9.
#     Tried to use 'Geometry'.
#     Error:  Can't load
ometry/Geometry.so' for module Geometry:
metry/Geometry.so: undefined symbol: hypotenuse at
/usr/lib/perl5/5.8.8/i586-linux-thread-multi/DynaLoader.pm line 230.

This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.

Re: XS help

Postby sisyphus359 » Sat, 26 Jul 2008 23:43:28 GMT

On Jul 25, 8:35m,  XXXX@XXXXX.COM  (Rajnikant)

> file: hypotenuse.>
> /* Func Definitio> */
> ouble hypotenuse(double x, dou>le y)
> eturn sqr>(x*x + >*y);

I would probably just create a Makefile.PL that looks like:

use ExtUtils::MakeMaker;
my %option> = (
  'NAME' => 'Geometry>,
  'VERSION' => '0.01'

# Remove the Makefile dependency. Causes problems on a few systems.
sub MY::makefile { '' }

a Geometry.pm that looks like:

package Geometry;
use strict;

require Exporter;
*import = \&Exporter::import;
require DynaLoader;

$Geometry::VERSION = '0.01';

DynaLoader::bootstrap Geometry $Geometry::VERSION;

@Geometry::EXPORT = ();
@Geometry::EXPORT_OK = ('hypotenuse');

sub dl_load_flags {0} # Prevent DynaLoader from complaining and


a Geometry.xs that looks like:

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

double hypotenuse(double x, double y) {
           return sqrt(x*x + y*y);
MODULE = Geometry	PACKAGE = Geometry


hypotenuse (x, y)
	double	x
	double	y


and a test.pl that looks like:

use warnings;
use strict;
use Geometry 'hypotenuse';

print "1..1\n";

if(hypotenuse(5, 12) == 13) {print "ok 1\n"}
else {print "not ok 1\n"}

I used InlineX::C2XS (needs Inline::C) to autogenerate the first 3 of
those 4 files - though there's some very minor hand editing that went
on as well wrt the Makefile.PL and Geometry.pm.
'test.pl' was written entirely by hand.
The source file that InlineX::C2XS used (./src/Geometry.c) looked

double hypotenuse(double x, double y) {
           return sqrt(x*x + y*y);


Similar Threads:

1.Perl C, XS help


I am trying port an Custom Perl module from one server to another. The
module uses C/XS and was built in 2001/2. I got the source and did
`perl Makefile.PL; make`. There was an error in one .c file:

store.c:592: error: 'my_perl' undeclared (first use in this function)
store.c:592: error: (Each undeclared identifier is reported only once
store.c:592: error: for each function it appears in.)

I solved that by adding

'static PerlInterpreter *my_perl;'  near the top of the file.

After make distclean; perl Makefile, make and the same error with a
different file. This time however, once I added the static declaration
I got this error:

store.c:13: error: expected '=', ',', ';', 'asm' or '__attribute__'
before '*' token

It refers to the static declaration mentioned above.

I am a super newbie when it comes to C and I know this might be
straying OT but does anyone know how I can make this static declartion
in the correct way or perhaps point me to a list that might be able to


2.Help w/Class::Date Date.xs

3.Help with xs: converting I32 to int ?

4.Problem using more than 1 module in Windows (XS) - please help

Hi all
	I have a problem that I am running into while using Perl XS to build
an interface to my C++ library. This is on a windows machine with perl
5.6.1. I was able to use PerlXS to expose out different 'c++
classes' that my API supports. I wrote the .XS files for each of
these objects and now I am able to make a simple test.pl file and use
these objects from Perl. The problem comes when I try to use more than
1 object (module) in a single .pl file. Here would an example

========== working example perl script  ================

use lib "C:/Documents and Settings/myusername/Desktop/perl
use MyDataReader;
my $dr = new MyDataReader("hsd_demo_pre");
$dr->execQuery("select * from bug");
print "fields: " . $dr->getFieldCount() . "\n";

================== perl script giving problem =============
use lib "C:/Documents and Settings/myusername/Desktop/perl
use MyDataReader;

use MyAdmin;   # Adding this line gives problems

my $dr = new MyDataReader("hsd_demo_pre");
$dr->execQuery("select * from bug");
print "fields: " . $dr->getFieldCount() . "\n";

========= Error Message ==================

C:\Documents and Settings\myusername\Desktop\perl experiment\api>perl
Can't load 'C:\Documents and Settings\ myusername \Desktop\perl
/MyAdmin.dll' for module MyAdmin: load_file:Attempt to access invalid
address at C
:/Perl/lib/DynaLoader.pm line 206.
Compilation failed in require at test.pl line 11.
BEGIN failed--compilation aborted at test.pl line 11.

So the problem shows up when I use more than one 'use' statements
in a perl script. Its important to note here that I can use the
'MyAdmin' module by itself just fine. So its not aproblem with that
module. The problem is only when I try to use more than 1 module in a
single perl script.

==================== Makefile.PL ===================
use ExtUtils::MakeMaker;
$CC = 'cl';
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile( 'NAME' => 'MyDataReader',
               'VERSION' => '0.10',
               'DEFINE'	=> '-TP -EHsc',     # e.g., '-DHAVE_SOMETHING'
               'CC' => $CC,
               'LDDLFLAGS' => '-nologo -libpath:"C:\Perl\lib\CORE"
			   'LIBC' => 'msvcrtd.lib',
			   'LDLOADLIBS' => 'oldnames.lib kernel32.lib user32.lib gdi32.lib
winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib
version.lib odbc32.lib odbccp32.lib msvcrtd.lib',
			   'CCFLAGS' => '-nologo -O1 -MDd -DNDEBUG -DWIN32 -D_CONSOLE
               'LD' => '$(CC)',
               'XSOPT' => '-C++',
			   'OPTIMIZE' => '-O1 -MDd -DNDEBUG',
               'PERM_RW' => '664',
               'PERM_RWX' => '775',
               'TYPEMAPS' => ['perlobject.map']    ,
			    'INC'      => "-Iinclude",
          	'MYEXTLIB' => 'lib\myexternalapi.lib'

========== end =========

5.Help - Perl, XS and global constructors

I have a third-party dynamic library that I'm trying to write an xsub
for.  It was written in C++, and it apparently has global constructors
that need to be initialized.  Building a static xsub works fine, but
the dynamic build always crashes in one function (naturally, it's a
function that needs to be called before almost all of the others in the
library).  With the static build running in wdb, I can actually see
code in the library being called from __do_global_ctors(), but not so
with a dynamic build, so I'm pretty sure it's a constructor problem.

Before I go into the gritty details, let me just ask the basic
question: can a dynamically loaded xsub be written for a library that
has global constructors that need to be initialized?

In my search for a solution, I came to believe that this was possible,
due to references to the CCsimple example in CookbookB.  It gives a
recipe for building a new perl executable that handles C++ constructors
(which I've done).  But how would perl know what constructors need to
be run, when the xsub (and hence the library) aren't loaded until the
perl interpreter starts running?  Did I misunderstand the CCsimple
example?  Note that my xsub code itself doesn't use c++, just the
library (and I only know that because it requires stdc++ to be linked

I'm running HPUX 11, with a perl 5.8.6 that I built myself.  I've tried
building perl and the xsub with the HP ANSI C compiler (we don't have
the c++ compiler), g++ (with ld for linking), and g++ (for both
compiling and linking, which of course eventually calls ld anyway).
They all seem to behave about the same.

Any suggestions/guidance?  I can give more details about the xsub once
someone confirms that this is indeed possible.


6. Calling multiple perl subroutines from XS procedure

7. Loading external module from XS file?

8. updated xs question

Return to PERL


Who is online

Users browsing this forum: No registered users and 45 guest