Use of uninitialized value in concatenation (.) or string

2008-07-25 Thread luke devon

Dear Friends,

Following error i am getting while its functioning. Could you please help me to 
find out what the error is ? 

Use of uninitialized value in concatenation (.) or string at /xxx.pl line 18, 
STDIN line 1.
Use of uninitialized value in concatenation (.) or string at /xxx.pl line 21, 
STDIN line 1.


#!/usr/bin/perl

 use DBI;
 use strict;
 use warnings;

  my $###  = ;
  my $ = ;
  my $  = ;
  my $  = ;
  my $  = ;
  my $### = ;
  my $### = ;

while (STDIN){
chomp;
($, $, $##, $#, $) = split(/-/);
print $# . - . $# . - . $ . - . $# . - . 
$# ;
}

$sql  = INSERT INTO Table(##, ##, ##, #, #, , 
#, #, , ##, #, , #) values (' . $ . ', ' . 
$ . ', ' . $## . ',' . $# . ', now(), ' . $### . ', '##', '##', 
'##', '##', '##', '##', 0);

$sql_x = DELETE FROM Table WHERE # = ' . $# . ' AND # = 
' . $## . ' AND # = ' . $ . ' ;

my $dbh = DBI-connect(dbi:mysql:DB;localhost,###,) || die Error 
Opening DataBase: $DBI::errstr\n;

if ( $###=~m#XXX# ){

$dbh-do($sql_x);
}else{
$dbh-do ($sql);
}

if ($dbh-err()) { die sql error $DBI::errstr\n; }

$dbh-disconnect();

Many Thanks
Luke


Send instant messages to your online friends http://uk.messenger.yahoo.com 

RE: Use of uninitialized value in concatenation (.) or string

2008-07-25 Thread Thomas Bätzler
luke devon [EMAIL PROTECTED] asked:
 Following error i am getting while its functioning. Could you 
 please help me to find out what the error is ? 
 
 Use of uninitialized value in concatenation (.) or string at 
 /xxx.pl line 18, STDIN line 1.
 Use of uninitialized value in concatenation (.) or string at 
 /xxx.pl line 21, STDIN line 1.

It does say so right in the error message: You are building a
new string by interpolating and concatenating strings and
variables and at least one of the variables you're using is
undefined.

Without any input and sensible variable names it's hard to say
where the exact problem ist, but I'd guess it's the input having
sometimes less fields than what you anticipated in the split
statement.

HTH,
Thomas

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




XS help

2008-07-25 Thread Rajnikant
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
components
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/GeometryNOK 1
#   Failed test 'use Geometry;'
#   in t/Geometry.t at line 9.
# Tried to use 'Geometry'.
# Error:  Can't load
'/SES/rajni/claudio/rajni/myModule/Code/factorial/Geometry/blib/arch/auto/Ge
ometry/Geometry.so' for module Geometry:
/SES/rajni/claudio/rajni/myModule/Code/factorial/Geometry/blib/arch/auto/Geo
metry/Geometry.so: undefined symbol: hypotenuse at
/usr/lib/perl5/5.8.8/i586-linux-thread-multi/DynaLoader.pm line 230.
 
Thanks
Rajni
 
 
 

DISCLAIMER
==
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.


XS

2008-07-25 Thread Patrick Dupre

Hello,

I am trying to pass a array of references on array to a c subroutine:
my @set_2d = ([0.0, 1.0], [1.1, 2.2], [3.1, 4.4]) ;
test::test([EMAIL PROTECTED]) ;

in xs I put:

typedef double floatArray ;

void * floatArrayPtr (int num) {
  SV * mortal ;
  mortal = sv_2mortal (NEWSV (0, num * sizeof (floatArray))) ;
  return SvPVX (mortal) ;
  }

double
spectrum_2d (avref)
AV * avref
PREINIT:
int len, ncols;
int i, j ;
SV ** elem ;
floatMatrix *matrix ;
AV** row ;
CODE:
len = av_len (avref) + 1 ;
printf (spectrum_2d: %d\n, len) ;
ncols = 2 ;
matrix = floatMatrixPtr (len) ;
for (i = 0 ; i  len ; i++) {
  matrix [i] = floatArrayPtr (ncols) ;
  }
for (i = 0 ; i  len ; i++) {
  row = av_fetch (avref, i , 0) ;
  if (row =! NULL) {
for (j = 0 ; j  ncols ; j++) {
  elem = av_fetch (*row, j , 0) ;
  if (elem == NULL) {
matrix [i] [j] = 0 ;
}
  else {
matrix [i] [j] = SvNV (*elem) ;
}
  }
}
  }
RETVAL = 0 ;
OUTPUT:
RETVAL

But it does not work,
If somebody could tell me what is wrong !

Regards.
--
---
==
 Patrick DUPRÉ  |   |
 Department of Chemistry|   |Phone: (44)-(0)-1904-434384
 The University of York |   |Fax:   (44)-(0)-1904-432516
 Heslington |   |
 York YO10 5DD  United Kingdom  |   |email: [EMAIL PROTECTED]
==
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Re: XS

2008-07-25 Thread Rob Dixon
Patrick Dupre wrote:
 Hello,
 
 I am trying to pass a array of references on array to a c subroutine:
 my @set_2d = ([0.0, 1.0], [1.1, 2.2], [3.1, 4.4]) ;
 test::test([EMAIL PROTECTED]) ;
 
 in xs I put:
 
 typedef double floatArray ;
 
 void * floatArrayPtr (int num) {
SV * mortal ;
mortal = sv_2mortal (NEWSV (0, num * sizeof (floatArray))) ;
return SvPVX (mortal) ;
}
 
 double
 spectrum_2d (avref)
  AV * avref
  PREINIT:
   int len, ncols;
   int i, j ;
   SV ** elem ;
   floatMatrix *matrix ;
   AV** row ;
  CODE:
   len = av_len (avref) + 1 ;
   printf (spectrum_2d: %d\n, len) ;
   ncols = 2 ;
   matrix = floatMatrixPtr (len) ;
   for (i = 0 ; i  len ; i++) {
 matrix [i] = floatArrayPtr (ncols) ;
 }
   for (i = 0 ; i  len ; i++) {
 row = av_fetch (avref, i , 0) ;
 if (row =! NULL) {
   for (j = 0 ; j  ncols ; j++) {
 elem = av_fetch (*row, j , 0) ;
 if (elem == NULL) {
   matrix [i] [j] = 0 ;
   }
 else {
   matrix [i] [j] = SvNV (*elem) ;
   }
 }
   }
 }
   RETVAL = 0 ;
  OUTPUT:
   RETVAL
 
 But it does not work,
 If somebody could tell me what is wrong !

There are a few things wrong with this. There is no typedef for floatMatrix for
instance, and =! isn't a valid C operator. But what is it supposed to do? It
seems to be copying a Perl array of arrays to the floatmatrix 'matrix', but then
just ignores that copy and returns 0.0.

Rob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




edit a file cause unexpected execution

2008-07-25 Thread William
Hello, I am editing the WordNet http://wordnet.princeton.edu/  dictionary files 
to add my own words into it. The database file of WordNet look like normal text 
file and I am editing it with vim, but whenever I add a word it causes the perl 
seek function to work incorrecly.  

Here are the first *TWO* lines of data.noun file with the parts that I have 
added on the first line, entity2 0
1740 03 n 02 entity 0 entity2 0 003 ~ 1930 n  ~ 2137 n
 ~ 04424418 n  | that which is perceived or known or inferred
to have its own distinct existence (living or nonliving)
1930 03 n 01 physical_entity 0 007 @ 1740 n  ~ 2452 n
 ~ 2684 n  ~ 7347 n  ~ 00020827 n  ~ 00029677 n
 ~ 14580597 n  | an entity that has physical existence



Happen in
WordNet::QueryData module at 
http://search.cpan.org/~jrennie/WordNet-QueryData-1.47/QueryData.pm
WordNet::QueryData::getSense function , line 612 - 613

612: seek $fh, $offset, 0;
613: my $line = $fh;


# $fh is the filehandle to data.noun
#Perl debugger
DB51 x $offset
0  1930
# Here is the part that causes the seek function get the wrong data,
DB48 x $line
0  'iving)  
#The $line suppose to be
1930 03 n 01 physical_entity 0 007 @ 1740 n  ~ 2452 n
 ~ 2684 n  ~ 7347 n  ~ 00020827 n  ~ 00029677 n
 ~ 14580597 n  | an entity that has physical existence


With these perl code it's enough to cause such an error
use WordNet::QueryData;
my $wn = new WordNet::QueryData;
print $wn-querySense(entity#n#1,hypo);

(getSense) Internal error: offset=1930 pos=n at 
/usr/local/lib/perl5/site_perl/5.10.0/WordNet/QueryData.pm line 622, GEN8 
line 2.


Is it because those files are not normal text file ? 
But according to them 
What is the format of the WordNet database?
The (ASCII) database format is well-documented. See WordNet documentation 
index, specifically WordNet man page: wndb.5WN.
I had spent more than 24 hours to solve this, but not still not clue, please 
guide me.
Thank you very much,

Regards,
William Kisman


Send instant messages to your online friends http://uk.messenger.yahoo.com

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: edit a file cause unexpected execution

2008-07-25 Thread Rob Dixon
William wrote:
 Hello, I am editing the WordNet http://wordnet.princeton.edu/  dictionary 
 files to add my own words into it. The database file of WordNet look like 
 normal text file and I am editing it with vim, but whenever I add a word it 
 causes the perl seek function to work incorrecly.  
 
 Here are the first *TWO* lines of data.noun file with the parts that I have 
 added on the first line, entity2 0
 1740 03 n 02 entity 0 entity2 0 003 ~ 1930 n  ~ 2137 n
  ~ 04424418 n  | that which is perceived or known or inferred
 to have its own distinct existence (living or nonliving)
 1930 03 n 01 physical_entity 0 007 @ 1740 n  ~ 2452 n
  ~ 2684 n  ~ 7347 n  ~ 00020827 n  ~ 00029677 n
  ~ 14580597 n  | an entity that has physical existence
 
 
 
 Happen in
 WordNet::QueryData module at 
 http://search.cpan.org/~jrennie/WordNet-QueryData-1.47/QueryData.pm
 WordNet::QueryData::getSense function , line 612 - 613
 
 612: seek $fh, $offset, 0;
 613: my $line = $fh;
 
 
 # $fh is the filehandle to data.noun
 #Perl debugger
 DB51 x $offset
 0  1930
 # Here is the part that causes the seek function get the wrong data,
 DB48 x $line
 0  'iving)  
 #The $line suppose to be
 1930 03 n 01 physical_entity 0 007 @ 1740 n  ~ 2452 n
  ~ 2684 n  ~ 7347 n  ~ 00020827 n  ~ 00029677 n
  ~ 14580597 n  | an entity that has physical existence
 
 
 With these perl code it's enough to cause such an error
 use WordNet::QueryData;
 my $wn = new WordNet::QueryData;
 print $wn-querySense(entity#n#1,hypo);
 
 (getSense) Internal error: offset=1930 pos=n at 
 /usr/local/lib/perl5/site_perl/5.10.0/WordNet/QueryData.pm line 622, GEN8 
 line 2.
 
 
 Is it because those files are not normal text file ? 
 But according to them 
 What is the format of the WordNet database?
 The (ASCII) database format is well-documented. See WordNet documentation 
 index, specifically WordNet man page: wndb.5WN.
 I had spent more than 24 hours to solve this, but not still not clue, please 
 guide me.
 Thank you very much,

Have you also modified the index.noun file to account for your changes?
index.noun contains a list of byte offsets into data.noun, and any changes to
the latter mean the former is invalid.

Alternatively, I wonder what platform you are working on? Records in the WordNet
files must be terminated by just a single \x0A. If you are working on a
non-Unix platform that uses a multi-character record separator then the records
will be a different length, so invalidating the index file.

HTH,

Rob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: edit a file cause unexpected execution

2008-07-25 Thread William
Thanks for the reply.

 Have you also modified the index.noun file to account for your changes?

 index.noun contains a list of byte offsets into data.noun, and any changes to
 the latter mean the former is invalid.

I have modified the index.noun too, 

 Alternatively, I wonder what platform you are working on? Records in the 
 WordNet
 files must be terminated by just a single \x0A. If you are working on a
 non-Unix platform that uses a multi-character record separator then the 
 records
 will be a different length, so invalidating the index file.

I am working on Linux william-pc 2.6.24-16-generic #1 SMP Thu Apr 10 13:23:42 
UTC 2008 i686 GNU/Linux

Ok, I got to admit something, after knowing the seek function, only today I 
realize how actually determine the synset id which is equivalient to byte 
offset that you said. Before this I thought the synset id is determined by some 
kind of database auto-increment id/ primary key thing. lol. 

Send instant messages to your online friends http://uk.messenger.yahoo.com

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: edit a file cause unexpected execution

2008-07-25 Thread William
Sorry, I accidentally clicked the send mail.

Thanks for the reply.

 Have you also modified the index.noun file to account for your changes?

 index.noun contains a list of byte offsets into data.noun, and any changes to
 the latter mean the former is invalid.

I have modified the index.noun too, 

 Alternatively, I wonder what platform you are working on? Records in the 
 WordNet
 files must be terminated by just a single \x0A. If you are working on a
 non-Unix platform that uses a multi-character record separator then the 
 records
 will be a different length, so invalidating the index file.

I am working on Linux william-pc 2.6.24-16-generic #1 SMP Thu Apr 10 13:23:42 
UTC 2008 i686 GNU/Linux

Ok,
I got to admit something, after knowing the seek function, only today I
realize how actually determine the synset id which is equivalient to
byte offset that you said. Before this I thought the synset id is
determined by some kind of database auto-increment id/ primary key
thing. lol.

Now I realized of course when I added let's say 3 character to the first line 
and when the seek function try to seek(FH, 1930, 0) , 
I will get 
g)\n1930 03 n 01 physical_entity 0 007 @ 1740 n  ~ 2452 n
 ~ 2684 n  ~ 7347 n  ~ 00020827 n  ~ 00029677 n
 ~ 14580597 n  | an entity that has physical existence

1740 03 n 02 entity 0 003 ~ 1930 n  ~ 2137 n  ~ 04424418 n 
 | that which is perceived or known or inferred to have its own distinct 
existence (living or nonliving)
1930 03 n 01 physical_entity 0 007 @ 1740 n  ~ 2452 n  ~ 
2684 n  ~ 7347 n  ~ 00020827 n  ~ 00029677 n  ~ 
14580597 n  | an entity that has physical existence

Not wonder it's invalid.

I wonder what is the reason they arrange the database in such a way ? Is it, it 
would make the lookup faster ? And what is that index.noun file used for when 
all the information in there is also in data.noun ?

So now how can I add new synonym words to the WordNet database without 
affecting the original offset bytes ? 

Thanks.


Send instant messages to your online friends http://uk.messenger.yahoo.com

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: XS

2008-07-25 Thread Patrick Dupre

Hello,

I am trying to pass a array of references on array to a c subroutine:
my @set_2d = ([0.0, 1.0], [1.1, 2.2], [3.1, 4.4]) ;
test::test([EMAIL PROTECTED]) ;

in xs I put:

typedef double floatArray ;

void * floatArrayPtr (int num) {
   SV * mortal ;
   mortal = sv_2mortal (NEWSV (0, num * sizeof (floatArray))) ;
   return SvPVX (mortal) ;
   }

double
spectrum_2d (avref)
 AV * avref
 PREINIT:
int len, ncols;
int i, j ;
SV ** elem ;
floatMatrix *matrix ;
AV** row ;
 CODE:
len = av_len (avref) + 1 ;
printf (spectrum_2d: %d\n, len) ;
ncols = 2 ;
matrix = floatMatrixPtr (len) ;
for (i = 0 ; i  len ; i++) {
  matrix [i] = floatArrayPtr (ncols) ;
  }
for (i = 0 ; i  len ; i++) {
  row = av_fetch (avref, i , 0) ;
  if (row =! NULL) {
for (j = 0 ; j  ncols ; j++) {
  elem = av_fetch (*row, j , 0) ;
  if (elem == NULL) {
matrix [i] [j] = 0 ;
}
  else {
matrix [i] [j] = SvNV (*elem) ;
}
  }
}
  }
RETVAL = 0 ;
 OUTPUT:
RETVAL

But it does not work,
If somebody could tell me what is wrong !


There are a few things wrong with this. There is no typedef for floatMatrix for
instance,

Sorry:
typedef double *floatMatrix ;

 and =! isn't a valid C operator.
Right, the compiler did not see it !!!
 But what is it supposed to do? It

For now, nothing, I need to fill my c array from the perl array (kind of 
2d array), when I will be able to do it, then I will finish.



seems to be copying a Perl array of arrays to the floatmatrix 'matrix', but then
just ignores that copy and returns 0.0.

Rob



--
---
==
 Patrick DUPRÉ  |   |
 Department of Chemistry|   |Phone: (44)-(0)-1904-434384
 The University of York |   |Fax:   (44)-(0)-1904-432516
 Heslington |   |
 York YO10 5DD  United Kingdom  |   |email: [EMAIL PROTECTED]
==
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Re: edit a file cause unexpected execution

2008-07-25 Thread Rob Dixon
William wrote:
 
 Thanks for the reply.
 
 Have you also modified the index.noun file to account for your changes?
 
 index.noun contains a list of byte offsets into data.noun, and any changes to
 the latter mean the former is invalid.
 
 I have modified the index.noun too, 
 
 Alternatively, I wonder what platform you are working on? Records in the 
 WordNet
 files must be terminated by just a single \x0A. If you are working on a
 non-Unix platform that uses a multi-character record separator then the 
 records
 will be a different length, so invalidating the index file.
 
 I am working on Linux william-pc 2.6.24-16-generic #1 SMP Thu Apr 10 13:23:42 
 UTC 2008 i686 GNU/Linux
 
 Ok,
 I got to admit something, after knowing the seek function, only today I
 realize how actually determine the synset id which is equivalient to
 byte offset that you said. Before this I thought the synset id is
 determined by some kind of database auto-increment id/ primary key
 thing. lol.
 
 Now I realized of course when I added let's say 3 character to the first line 
 and when the seek function try to seek(FH, 1930, 0) , 
 I will get 
 g)\n1930 03 n 01 physical_entity 0 007 @ 1740 n  ~ 2452 n
  ~ 2684 n  ~ 7347 n  ~ 00020827 n  ~ 00029677 n
  ~ 14580597 n  | an entity that has physical existence
 
 1740 03 n 02 entity 0 003 ~ 1930 n  ~ 2137 n  ~ 04424418 
 n  | that which is perceived or known or inferred to have its own 
 distinct existence (living or nonliving)
 1930 03 n 01 physical_entity 0 007 @ 1740 n  ~ 2452 n  ~ 
 2684 n  ~ 7347 n  ~ 00020827 n  ~ 00029677 n  ~ 
 14580597 n  | an entity that has physical existence
 
 Not wonder it's invalid.
 
 I wonder what is the reason they arrange the database in such a way ? Is it, 
 it would make the lookup faster ? And what is that index.noun file used for
 when all the information in there is also in data.noun ?
 
 So now how can I add new synonym words to the WordNet database without
 affecting the original offset bytes ?

You clearly haven't come across file indexing before! Using seek() to locate a
record is incomparably faster than reading through it until you find the data
you need.

Using the file offset as a record ID is a good idea because

- It is bound to be unique
- it is easy to verify that the data hasn't been corrupted

The separate index.noun file is there to make it quick to find all records in
data.noun that apply to a given word.

Editing the database is a non-trivial task. You've found the documentation
already, so take a look at that and write something that allows you to move data
around while keeping the record IDs valid.

Rob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: System Call Help

2008-07-25 Thread masterpoet
On Jul 24, 7:39 pm, [EMAIL PROTECTED] (Peng Kyo) wrote:
 On Fri, Jul 25, 2008 at 3:22 AM,  [EMAIL PROTECTED] wrote:
  Greets Guys

  Trying to Make a system from perl to use the sort.

  # @args = ('c:\windows\system32\sort.exe C\logs\');
  # system(@args) == 0
  #  or die system @args failed:$?

 rather than calling an external system commands, you should use Perl's
 built-in sort function, which expresses well under this case. see
 perldoc -f sort for helps.

 --
 Regards,
 Jeff. - [EMAIL PROTECTED]

So how would that work? Then end result is the joining of two log
files into one master file.

But because both of these log files are similar in terms of servers,
Users either get directed to one or the other.

So when I join both files, I want it sorted uniquely without losing
any data.
I was also toying around with this

my @args = (
  'c:\windows\system32\sort.exe',
  'xferlog.log',);
eval {
  system(@args)
};
if ($@) {
 warn there was an error\n;
}

But this is the Unix Sort that I need

sort -Mk 2,2 -k 3,3n xferlog.??.nsun2 xferlog.??.nsun3 -o xferlog.??

Thats how Unix will sort it.

-Thanks


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: XS help

2008-07-25 Thread sisyphus
On Jul 25, 8:35 pm, [EMAIL PROTECTED] (Rajnikant)
wrote:
 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);
      }


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

--
use ExtUtils::MakeMaker;
my %options = (
  'NAME' = 'Geometry',
  'VERSION' = '0.01'
);
WriteMakefile(%options);

# 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
croaking

1;
--

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

PROTOTYPES: DISABLE


double
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
like:

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


Cheers,
Rob


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Replacement using variable

2008-07-25 Thread V.Ramkumar

Hi,

Any one suggest me, what is the error in my below code, Not any error when
run, But unable to get the search value in replacement.

$content=~s/$allelm/\1 xml:id=.$idseq++/egsi;

Here $allelm contains element list, (para|quote|list).

I am getting output as a junk for \1.

Regards,
Ramkumar



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Replacement using variable

2008-07-25 Thread Rob Dixon
V.Ramkumar wrote:
 Hi,
 
 Any one suggest me, what is the error in my below code, Not any error when
 run, But unable to get the search value in replacement.
 
 $content=~s/$allelm/\1 xml:id=.$idseq++/egsi;
 
 Here $allelm contains element list, (para|quote|list).
 
 I am getting output as a junk for \1.

perldoc perlre says this

   Warning on \1 vs $1
 Some people get too used to writing things like:
 
 $pattern =~ s/(\W)/\\\1/g;
 
 This is grandfathered for the RHS of a substitute to avoid shocking the
 sed addicts, but it's a dirty habit to get into. That's because in
 PerlThink, the righthand side of an s/// is a double-quoted string.
 \1 in the usual double-quoted string means a control-A. The customary
 Unix meaning of \1 is kludged in for s///. However, if you get into
 the habit of doing that, you get yourself into trouble if you then add
 an /e modifier.
 
 s/(\d+)/ \1 + 1 /eg;# causes warning under -w
 
 Or if you try to do
 
 s/(\d+)/\1000/;
 
 You can't disambiguate that by saying \{1}000, whereas you can fix it
 with ${1}000. The operation of interpolation should not be confused
 with the operation of matching a backreference. Certainly they mean two
 different things on the *left* side of the s///.

Rob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Replacement using variable

2008-07-25 Thread Mr. Shawn H. Corey
On Fri, 2008-07-25 at 14:27 +0530, V.Ramkumar wrote:
 Hi,
 
 Any one suggest me, what is the error in my below code, Not any error when
 run, But unable to get the search value in replacement.
 
 $content=~s/$allelm/\1 xml:id=.$idseq++/egsi;
 
 Here $allelm contains element list, (para|quote|list).
 
 I am getting output as a junk for \1.
 
 Regards,
 Ramkumar
 
 
 

Use $1 as in:

  $content=~s/($allelm)/$1 xml:id=.$idseq++/egsi;

Note the parentheses.  Not only is the substitution clearer but it will
work when $allelm is a single item, as in:

  $allelm = 'para';




-- 
Just my 0.0002 million dollars worth,
  Shawn

Where there's duct tape, there's hope.

Perl is the duct tape of the Internet.
Hassan Schroeder, Sun's first webmaster


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: edit a file cause unexpected execution

2008-07-25 Thread William
 You clearly haven't come across file indexing before! Using seek() to locate a

 record is incomparably faster than reading through it until you find the data
 you need.
 
 Using the file offset as a record ID is a good idea because

 - It is bound to be unique
 - it is easy to verify that the data hasn't been corrupted

 The separate index.noun file is there to make it quick to find all records in
 data.noun that apply to a given word.

 Editing the database is a non-trivial task. You've found the documentation
 already, so take a look at that and write something that allows you to move 
 data
 around while keeping the record IDs valid.


Thank you that helps me understand a lot, I have stare at the documentation 
quite long but I still can't find the way of editing the data without affecting 
the byte offset. I would need to customize the module WordNet::QueryData 
according the the new things that I added too.

Thank you,


Send instant messages to your online friends http://uk.messenger.yahoo.com

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




while trying to learn pack

2008-07-25 Thread Richard Lee
I am begining to read bit of low level(assembly) book to just gain some 
knoweldge on inner workings of memory.


My quesiton is, if machine is 32 bit, even if it's accessing string 'A', 
it will have to fetch 32 bit (instead of 8 bit that requires to make 
that letter A ) ?


I know this is not a mailing list for this but i figure since it's 
closely related to pack, i thought someone would clarify for me.


I am reading step by step assembly language... I am not sure i will 
read the whole thing but i just want to get better inner working of 
memory as my c book didn't do enough justice.


Please help.

thanks!

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: XS

2008-07-25 Thread Rob Dixon
Patrick Dupre wrote:
 Hello,
 
 I am trying to pass a array of references on array to a c subroutine:
 my @set_2d = ([0.0, 1.0], [1.1, 2.2], [3.1, 4.4]) ;
 test::test([EMAIL PROTECTED]) ;
 
 in xs I put:
 
 typedef double floatArray ;
 
 void * floatArrayPtr (int num) {
SV * mortal ;
mortal = sv_2mortal (NEWSV (0, num * sizeof (floatArray))) ;
return SvPVX (mortal) ;
}
 
 double
 spectrum_2d (avref)
  AV * avref
  PREINIT:
   int len, ncols;
   int i, j ;
   SV ** elem ;
   floatMatrix *matrix ;
   AV** row ;
  CODE:
   len = av_len (avref) + 1 ;
   printf (spectrum_2d: %d\n, len) ;
   ncols = 2 ;
   matrix = floatMatrixPtr (len) ;
   for (i = 0 ; i  len ; i++) {
 matrix [i] = floatArrayPtr (ncols) ;
 }
   for (i = 0 ; i  len ; i++) {
 row = av_fetch (avref, i , 0) ;
 if (row =! NULL) {
   for (j = 0 ; j  ncols ; j++) {
 elem = av_fetch (*row, j , 0) ;
 if (elem == NULL) {
   matrix [i] [j] = 0 ;
   }
 else {
   matrix [i] [j] = SvNV (*elem) ;
   }
 }
   }
 }
   RETVAL = 0 ;
  OUTPUT:
   RETVAL
 
 But it does not work,
 If somebody could tell me what is wrong !

OK, the main problem is that

  row = av_fetch(avref, i , 0);

returns a **SV that is a reference to an array, not an array. So when you go
ahead to write

  elem = av_fetch (*row, j , 0);

you're passing a *SV instead of a *AV. You need to dereference it like

  rowref = av_fetch(avref, i , 0);
  row = (AV *)SvRV(*rowref);
  elem = av_fetch (row, j , 0);

Below is a working XS file.

HTH,

Rob



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

typedef double floatArray;

void *floatArrayPtr(int num)
{
  SV *mortal = NEWSV(0, num * sizeof(floatArray));
  sv_2mortal(mortal);
  return SvPVX(mortal);
}

typedef floatArray *floatMatrix;

void *floatMatrixPtr(int num)
{
  SV *mortal =  NEWSV(0, num * sizeof(floatMatrix));
  sv_2mortal(mortal);
  return SvPVX(mortal);
}

MODULE = Arrays PACKAGE = Arrays

void
spectrum_2d(avref)
AV *avref

  PREINIT:
int nrows, ncols;
int i, j;
AV *row;
SV **rowref, **elem;
floatMatrix *matrix;

  CODE:

if (avref == NULL || SvTYPE(avref) != SVt_PVAV)
return;

nrows = av_len(avref) + 1;
matrix = floatMatrixPtr(nrows);

for (i = 0; i  nrows; i++) {

  rowref = av_fetch(avref, i, 0);

  if (rowref == NULL || !SvROK(*rowref))
  {
matrix[i] = NULL;
continue;
  }

  row = (AV *)SvRV(*rowref);
  ncols = av_len(row) + 1;
  matrix[i] = floatArrayPtr(ncols);

  for (j = 0; j  ncols; j++)
  {
elem = av_fetch(row, j , 0);
if (SvNOK(*elem)) matrix[i][j] = SvNV(*elem);
else if (SvIOK(*elem)) matrix[i][j] = SvIV(*elem);
else matrix[i][j] = 0;
  }
}



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: while trying to learn pack

2008-07-25 Thread Rob Dixon
Richard Lee wrote:

 I am begining to read bit of low level(assembly) book to just gain some 
 knoweldge on inner workings of memory.
 
 My quesiton is, if machine is 32 bit, even if it's accessing string 'A', 
 it will have to fetch 32 bit (instead of 8 bit that requires to make 
 that letter A ) ?
 
 I know this is not a mailing list for this but i figure since it's 
 closely related to pack, i thought someone would clarify for me.
 
 I am reading step by step assembly language... I am not sure i will 
 read the whole thing but i just want to get better inner working of 
 memory as my c book didn't do enough justice.

It is the addressing that is 32-bit, not the data. Assembly languages will
generally have instructions like

 - move byte
 - move word
 - move longword
 - move quadword

and so on.

The main difference between machine architecture is the order in which bytes
appear in multi-byte binary values. Most have the least-significant byte at the
lowest address, but Motorola processors and a few others have the order
reversed. You will see provision for the different ordering in the formats
available in a call to pack.

HTH,

Rob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: while trying to learn pack

2008-07-25 Thread John W. Krahn

Richard Lee wrote:
I am begining to read bit of low level(assembly) book to just gain some 
knoweldge on inner workings of memory.


My quesiton is, if machine is 32 bit, even if it's accessing string 'A', 
it will have to fetch 32 bit (instead of 8 bit that requires to make 
that letter A ) ?


It depends on the CPU.  An Intel compatible CPU has instructions to 
access 8 bit values from memory but some CPUs can only access 32 bit 
aligned data.


I know this is not a mailing list for this but i figure since it's 
closely related to pack, i thought someone would clarify for me.


It is not really related to pack() as pack() is a high level function 
that can hide the details of the CPUs addressing problems.


I am reading step by step assembly language... I am not sure i will 
read the whole thing but i just want to get better inner working of 
memory as my c book didn't do enough justice.



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.-- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: XS

2008-07-25 Thread Patrick Dupre

Thank,

Regards


Patrick Dupre wrote:

Hello,

I am trying to pass a array of references on array to a c subroutine:
my @set_2d = ([0.0, 1.0], [1.1, 2.2], [3.1, 4.4]) ;
test::test([EMAIL PROTECTED]) ;

in xs I put:

typedef double floatArray ;

void * floatArrayPtr (int num) {
   SV * mortal ;
   mortal = sv_2mortal (NEWSV (0, num * sizeof (floatArray))) ;
   return SvPVX (mortal) ;
   }

double
spectrum_2d (avref)
 AV * avref
 PREINIT:
int len, ncols;
int i, j ;
SV ** elem ;
floatMatrix *matrix ;
AV** row ;
 CODE:
len = av_len (avref) + 1 ;
printf (spectrum_2d: %d\n, len) ;
ncols = 2 ;
matrix = floatMatrixPtr (len) ;
for (i = 0 ; i  len ; i++) {
  matrix [i] = floatArrayPtr (ncols) ;
  }
for (i = 0 ; i  len ; i++) {
  row = av_fetch (avref, i , 0) ;
  if (row =! NULL) {
for (j = 0 ; j  ncols ; j++) {
  elem = av_fetch (*row, j , 0) ;
  if (elem == NULL) {
matrix [i] [j] = 0 ;
}
  else {
matrix [i] [j] = SvNV (*elem) ;
}
  }
}
  }
RETVAL = 0 ;
 OUTPUT:
RETVAL

But it does not work,
If somebody could tell me what is wrong !


OK, the main problem is that

 row = av_fetch(avref, i , 0);

returns a **SV that is a reference to an array, not an array. So when you go
ahead to write

 elem = av_fetch (*row, j , 0);

you're passing a *SV instead of a *AV. You need to dereference it like

 rowref = av_fetch(avref, i , 0);
 row = (AV *)SvRV(*rowref);
 elem = av_fetch (row, j , 0);

Below is a working XS file.

HTH,

Rob



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

typedef double floatArray;

void *floatArrayPtr(int num)
{
 SV *mortal = NEWSV(0, num * sizeof(floatArray));
 sv_2mortal(mortal);
 return SvPVX(mortal);
}

typedef floatArray *floatMatrix;

void *floatMatrixPtr(int num)
{
 SV *mortal =  NEWSV(0, num * sizeof(floatMatrix));
 sv_2mortal(mortal);
 return SvPVX(mortal);
}

MODULE = Arrays PACKAGE = Arrays

void
spectrum_2d(avref)
   AV *avref

 PREINIT:
   int nrows, ncols;
   int i, j;
   AV *row;
   SV **rowref, **elem;
   floatMatrix *matrix;

 CODE:

   if (avref == NULL || SvTYPE(avref) != SVt_PVAV)
   return;

   nrows = av_len(avref) + 1;
   matrix = floatMatrixPtr(nrows);

   for (i = 0; i  nrows; i++) {

 rowref = av_fetch(avref, i, 0);

 if (rowref == NULL || !SvROK(*rowref))
 {
   matrix[i] = NULL;
   continue;
 }

 row = (AV *)SvRV(*rowref);
 ncols = av_len(row) + 1;
 matrix[i] = floatArrayPtr(ncols);

 for (j = 0; j  ncols; j++)
 {
   elem = av_fetch(row, j , 0);
   if (SvNOK(*elem)) matrix[i][j] = SvNV(*elem);
   else if (SvIOK(*elem)) matrix[i][j] = SvIV(*elem);
   else matrix[i][j] = 0;
 }
   }





--
---
==
 Patrick DUPRÉ  |   |
 Department of Chemistry|   |Phone: (44)-(0)-1904-434384
 The University of York |   |Fax:   (44)-(0)-1904-432516
 Heslington |   |
 York YO10 5DD  United Kingdom  |   |email: [EMAIL PROTECTED]
==
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/