Greetings, monks.

While playing with Inline::C, I whipped up this little bit of code. I thought 'hmm, that would make a good Inline::C demo for someone who's never used the module before.'

I know it's not much more than Inline::C-Cookbook, but in the spirit of TIMTOWTDI, ...

#!/usr/bin/perl -w use strict; use Inline 'C'; explain($_) for qw( foo bar bat baz qux ); __DATA__ __C__ /* don't need to include std C headers... perl.h header (included by default with Inline) includes them */ /* define this first so explain() can see it */ char *inflect(int num) { return num == 1 ? "st" : num == 2 ? "nd" : num == 3 ? "rd" : "th"; } void explain(char *var) { static int i = 1; printf("%s is the %d%s meta-syntactic variable.\n", var, i, inflect(i) ); ++i; }

email: perl -e 'print reverse map { chr( ord($_)-1 ) } split //, "\x0bufo/hojsfufqAofc";'

In reply to Inline::C demonstration for C programmers by missingthepoint

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.