use Inline C => q[

void print_hi(  ) {
     puts("Hi, world!");
}

];

print_hi(  );
---------------------------------
Pozostay ci 2 ycia; wynik 1500, masz 15 sztuk zota.
---------------------------------
[ycia: 2 XP: 1500 GP: 15]
---------------------------------
my $pattern = $user_pattern ||
              "Pozostay ci %i ycia; wynik %04i, masz %2i sztuk zota";
printf $pattern, $lives, $xp, $gp;
---------------------------------
char* score_format(char* pref_format, char* user_format) {
      return fmtcheck(user_format, pref_format);
}
---------------------------------
use Inline C;

my $pref_format = "Pozostay ci %i ycia; wynik %04i, masz %2i sztuk zota";
my ($lives, $score, $gp) = (3, 2500, 50);

my $user_format = "[ycia: %i, XP: %i, GP: %i]";

printf(score_format($pref_format, $user_format), $lives, $score, $gp);

_ _END_ _ 
_ _C_ _
#include <stdio.h>

char* score_format(char* pref_format, char* user_format) { 
      return fmtcheck(user_format, pref_format); 
}
---------------------------------
int count_alpha(char* foo) {
    int i = 0; 
    do {
     if (isalpha(*foo)) i++;
    } while (*foo++);
    return i;
}

use Inline C;

use Benchmark;
$test = "a b cd e fg" x 10000;

timethese(10000,
    {
      Perl => sub { $test =~ tr/[a-zA-Z]//; },
      C    => sub { count_alpha ($test) }
    }
)

_ _DATA_ _
_ _C_ _

int count_alpha(char* foo) {
    int i = 0; 
    do {
     if (isalpha(*foo)) i++;
    } while (*foo++);
    return i;
}
---------------------------------
Benchmark: timing 10000 iterations of C, Perl...
         C: 24 wallclock secs (20.80 usr +  0.15 sys = 20.95 CPU) @ 477.33/s (n=10000)
      Perl: 10 wallclock secs ( 8.05 usr +  0.04 sys =  8.09 CPU) @ 1236.09/s (n=10000)
---------------------------------
use IO::File; 
use Inline C => <<'EOT';
int blessed (SV* sv) {
    if (SvMAGICAL(sv)) 
        mg_get(sv);     /* Przywoujemy FETCH, etc. jeli jest powizanie */

    return sv_isobject(sv);
} 
EOT
 
my $a = \123; 
my $b = IO::File->new; 
 
print "\$a jest bogosawionym (blessed) odwoaniem\n" if blessed($a); 
print "\$b jest bogosawionym (blessed) odwoaniem\n" if blessed($b);
---------------------------------
$b jest bogosawionym (blessed) odwoaniem
---------------------------------
void dump_values(SV* sv) {
    STRLEN len;

    printf("As a float: %f\n", SvNV(sv));
    printf("As an integer: %i\n", SvIV(sv));
    printf("As a string: %s\n", SvPV(sv, len));
}
---------------------------------
my $a = "abc";
for (1..10) {
    $a .= "d";
    chop $a;
}
---------------------------------
$a = "5";
---------------------------------
$b = $a + 10;
---------------------------------
$a .= "abc";
---------------------------------
void dodgify(SV* sv) {
     SvTAINTED_on(sv);
}

void blow_away_all_the_security_in_my_program(SV* sv) {
     SvTAINTED_off(sv);
}
---------------------------------
{
    my $f = IO::Handle->new;
}
---------------------------------
{
    my $f = IO::Handle->new;
    $My::Copy = $f;
}
---------------------------------
int immortalize(SV* sv) {
    SvREFCNT_inc(sv);
    return SvREFCNT(sv);
}
---------------------------------
void kill_kill_kill(SV* sv) {
    SvREFCNT(sv) = 1;
    SvREFCNT_dec(sv);
}
---------------------------------
SV* tainted(SV* sv) {
    if (SvTAINTED(sv))
       return &PL_sv_yes;
    else
       return &PL_sv_no;
}
---------------------------------
if (SvTRUE(get_sv("MyModule::DEBUG", TRUE")))
   printf("XXX Przekazywanie kontroli do funkcji biblioteki\n");
---------------------------------
use Inline C => q{

void print_array(SV* arg1, ... ) {
     Inline_Stack_Vars;
     int i;

     for (i=0 ; i < Inline_Stack_Items ; i++) {
         printf("Argumentem %ith bdzie %s\n", i,
                 SvPV_nolen(Inline_Stack_Item(i));
     }
}

};

print_array("Witam", 123, "ryba", 0.12);
---------------------------------
% perl -le '$!=3; print $!; print $!+0'

No such process
3
---------------------------------
use Inline C => q{

void bothvars (SV* var) {
     Inline_Stack_Vars;
     Inline_Stack_Reset;
     if (SvPOK(var) && SvIOK(var)) { /* dwuwartociowy */
         Inline_Stack_Push(sv_2mortal(newSViv(SvIV(var)))); /* Posyamy na stos liczb */
     }
     Inline_Stack_Push(var); /* Posyamy na stos acuch */
     Inline_Stack_Done;
}

};

use Scalar::Util qw(dualvar);

my $var = dualvar(10, "Hello");
print "$_\n" for bothvars($var);
---------------------------------
    if (SvROK(sv) && (SvTYPE(SvRV(sv)) =  = SVt_PVAV))
        keys = (AV*)SvREFCNT_inc(SvRV(sv));
---------------------------------
    for (i = 0; i <= av_len(array); i++) {
        SV* elem;
        ...
    }
---------------------------------
    for (i = 0; i <= av_len(array); i++) {
        SV** elem_p = av_fetch(array, i, 0); 
        SV* elem;
        if (elem_p)
            elem = *elem_p;
        ...
    }
---------------------------------
my @array;
$array[3] = "Hej, witam!";
---------------------------------
    SV** base = AvARRAY(array);
    for (i = 0; i <= av_len(array); i++) {
        SV* elem = base[i];
        if (elem)
            printf("Element %i to %s\n", i, SvPV_nolen(elem));
    }
---------------------------------
    for (i = 0; i <= av_len(array); i++) {
        SV** elem_p = av_fetch(array, i, 0); 
        if (elem_p) {
            SV* elem = elem_p;
            sv_setiv(elem, SvIV(elem) + 1); /* dodajemy 1 do kadego elementu */
        }
    }
---------------------------------
     svp = hv_fetch(action, "ffactor", 7, FALSE);
     info->db_HA_ffactor = svp ? SvIV(*svp) : 0;

     svp = hv_fetch(action, "nelem", 5, FALSE);
     info->db_HA_nelem = svp ? SvIV(*svp) : 0;

     svp = hv_fetch(action, "bsize", 5, FALSE);
     info->db_HA_bsize = svp ? SvIV(*svp) : 0;
---------------------------------
      SV** new_sv = hv_fetch(hash, "message", 7, TRUE);
      if (!new_sv)
          croak("Co sie tutaj w takim razie stao?");
      sv_setpv(*new_sv, "Hej, witam!");
---------------------------------
      SV* message = newSVpv("Hej, witam!", 9);
      hv_store(hash, "message", message, 0);
---------------------------------
use Inline C => q{

#define OVECCOUNT 30  
#include <pcre.h>

int pcregrep( char* regex, char* string ) {
   pcre *re;
   const char *error;
   int rc, i, erroffset;
   int ovector[OVECCOUNT];

   re = pcre_compile( regex, 0, &error, &erroffset, NULL );
   if (re =  = NULL) 
     croak("Kompilacja PCRE nie powioda si dla przesunicia %d: %s\n", erroffset,
error);

   rc = pcre_exec( re, NULL, string, (int)strlen(string), 0, 0,
                   ovector, OVECCOUNT );

   if (rc < 0) {
      /* Dopasowanie nie powiodo si: zajmujemy si bdami */
       if (rc =  = PCRE_ERROR_NOMATCH)
           return 0;

       croak("Bd dopasowania %d\n", rc);
   }

   return 1;
}

};
---------------------------------
use Inline C => Config => LIBS => '-L/sw/lib -lpcre' => INC => '-I/sw/include';
---------------------------------
use Inline C => Config => LIBS => '-L/sw/lib -lpcre' => INC => '-I/sw/include';
use Inline C => q{

#define OVECCOUNT 30
#include <pcre.h>
/* Tutaj kod dugiej, skomplikowanej funkcji, ktr widzielimy wczeniej. */
};

if (pcregrep("f.o", "foobar")) {
    print "Dopasowano!\n";
} else { 
    print "Brak dopasowania!\n"; 
}
---------------------------------
use Inline C => Config => LIBS => '-L/sw/lib -lpcre' => 
                          INC => '-I/sw/include' =>
                          ENABLE => AUTOWRAP;
use Inline C => "char* pcre_version(  );";

print "Uywamy pcre w wersji ", pcre_version(  ), "\n";
# Uywamy pcre w wersji 3.9 02-Jan-2002
---------------------------------
use Inline C => "char* pcre_version(void)";
---------------------------------
pcreversion_c1dc.c: In function `pcre_version':
pcreversion_c1dc.c:20: parse error before '{' token
pcreversion_c1dc.c:21: parameter `sp' is initialized
pcreversion_c1dc.c:21: parameter `mark' is initialized
...

A problem was encountered while attempting to compile and install your
Inline C code. The command that failed was:
  make > out.make 2>&1

The build directory was:
/Users/simon/_Inline/build/pcreversion_c1dc

To debug the problem, cd to the build directory, and inspect the
output files.
---------------------------------
...
#include "INLINE.h"
char* pcre_version(void)
#line 16 "pcreversion_c1dc.c"
#ifdef _ _cplusplus
extern "C"
#endif
XS(boot_pcreversion_c1dc)
...
---------------------------------
Can't locate auto/main/pcre_versio.al in @INC (@INC contains:
/Users/simon/_Inline/lib /System/Library/Perl/darwin
/System/Library/Perl /Library/Perl/darwin /Library/Perl /Library/Perl
/Network/Library/Perl/darwin /Network/Library/Perl
/Network/Library/Perl .) at pcreversion line 6
---------------------------------
% perl -MInline=noclean pcreversion
---------------------------------
% perl -MInline=Force,NoClean,Info ~/pcreversion


Information about the processing of your Inline C code:

Your source code needs to be compiled. I'll use this build directory:
/Users/simon/_Inline/build/pcreversion_5819

and I'll install the executable as:
/Users/simon/_Inline/lib/auto/pcreversion_5819/pcreversion_5819.bundle

No C functions have been successfully bound to Perl.
---------------------------------
% h2xs -n My::Thingy

Writing My/Thingy/Thingy.pm
Writing My/Thingy/Thingy.xs
Writing My/Thingy/Makefile.PL
Writing My/Thingy/test.pl
Writing My/Thingy/Changes
Writing My/Thingy/MANIFEST

---------------------------------
% h2xs -XAn My::Thingy
Writing My/Thingy/Thingy.pm
Writing My/Thingy/Makefile.PL
Writing My/Thingy/test.pl
Writing My/Thingy/Changes
Writing My/Thingy/MANIFEST
---------------------------------
our $VERSION="1.01";

use Inline VERSION => '1.01',
              NAME => 'My::Thingy';
---------------------------------
use Inline Python => q{
import os
def orig_path(  ):
    return os.defpath.split(os.pathsep)
};

print "$_\n" for orig_path(  );
---------------------------------
use Inline Python => q{
from quopri import encodestring
};

print encodestring("quoted=printable"); # quoted=3Dprintable
---------------------------------
use Inline Python => q{
from robotparser import RobotFileParser
};

my $parser= RobotFileParser->new(  );
$parser->set_url('http://www.musi-cal.com/robots.txt');
$parser->read(  );
# ...
---------------------------------
use Inline Python => q{

def callperl(  ):
    print "Tu mwi Python..."
    perl.hi_world(  )
};

sub hi_world { print "Halo! Jestem w Perlu!\n" }

callperl(  );
---------------------------------
array = ["Halo", "witam", "Ruby!"]
array.each { |x| puts x }
---------------------------------
object->each(sub { print $_[0] });

---------------------------------
$object->iter(sub { print $_[0] })->each;
---------------------------------
void main(void) {
     printf("Halo C!\n");
}
---------------------------------
#!/usr/bin/cpr

void main(void) {
     print("Halo C!\n");
}
---------------------------------
#!/usr/bin/perl

use Inline C => q{

void main(void) { 
     printf("Halo C!\n");
}

};

main(  )
---------------------------------
use Inline C => Config => ENABLE => STRUCTS;
---------------------------------
