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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Inline::C demonstration for C programmers
by lidden (Curate) on Sep 01, 2008 at 04:07 UTC | |
by missingthepoint (Friar) on Sep 01, 2008 at 07:05 UTC | |
by ikegami (Patriarch) on Sep 01, 2008 at 23:14 UTC | |
by missingthepoint (Friar) on Sep 03, 2008 at 02:07 UTC | |
by ikegami (Patriarch) on Sep 01, 2008 at 06:27 UTC | |
by syphilis (Archbishop) on Sep 01, 2008 at 06:16 UTC | |
by sasdrtx (Friar) on Sep 01, 2008 at 13:16 UTC |