in reply to Re: Inline CPP undefined subroutine
in thread Inline CPP undefined subroutine
Or, for portability, you can accompany the Inline::CPP script with a separate typemap (named, eg my.typemap) that contains that line - in which case you need to tell Inline::CPP the name of that typemap. (See rewritten script below.)string T_PV
Here's the script I ran - modified to print, line by line, the number of Cs and Gs in any plain text input file:string MYPV INPUT MYPV $var = ($type)SvPV_nolen($arg)
Cheers,use strict; use warnings; my $file = $ARGV[0]; open (my $fh, "<", "$file") or die "Could not open < $file"; use Inline 'CPP' => Config => BUILD_NOISY => 1, TYPEMAPS => './my.typemap'; use Inline 'CPP' => << 'END'; using namespace std; int countGC(string gcString) { int res(0); for (int i = 0; i < gcString.length(); i++) { if (gcString[i] == 'C' || gcString[i] == 'G') { res++; } } return res; } END while (my $line = <$fh>){ printf ("%d\n", countGC($line)); } close $fh;
|
|---|