Filter::cpp(3pm)
β¨ Filter::cpp β cpp source filter β¨
okay so like. bestie. this is Filter::cpp, a cpp source filter, and it's genuinely so much fun. it's a Perl module from the User Contributed Perl Documentation crew, and it's giving "let me sneak the C pre-processor into your Perl script" energy π
π¦ SYNOPSIS π¦
use Filter::cpp ;
that's it. that's the whole invite. one line and you're in π«Ά
πΈ DESCRIPTION πΈ
so here's the tea: this source filter pipes the current source file through the C pre-processor (cpp) β if it is available. if cpp isn't around, no slay for you, sorry babe π
and like every source filter ever, its scope is limited to the current source file only. it does not spread. it does not travel. every single file you want processed by the filter has to have its own
use Filter::cpp ;
near the top. yes, every file. no shortcuts, no cap π
here's an example script that uses the filter, look at her go:
use Filter::cpp ;
#define FRED 1
$a = 2 + FRED ;
print "a = $a\n" ;
#ifdef FRED
print "Hello FRED\n" ;
#else
print "Where is FRED\n" ;
#endif
and here's what it outputs, iconic behaviour honestly:
a = 3
Hello FRED
see?? FRED got pre-processed into 1, 2 + 1 is 3, and the #ifdef did its little conditional moment and picked the Hello FRED branch. the #else never got a turn. rip to Where is FRED π
and okay, this next example is the moment. it was provided by Michael G Schwern, and it shows a clever way to get Perl to use a C pre-processor macro when the Filter::cpp module is available, or to use a Perl sub when it is not:
# use Filter::cpp if we can.
BEGIN { eval 'use Filter::cpp' }
sub PRINT {
my($string) = shift;
#define PRINT($string) \
(print $string."\n")
}
PRINT("Mu");
the way that BEGIN { eval 'use Filter::cpp' } just tries it and gracefully moves on if it can't?? main character energy fr fr π both worlds, one script, no drama.
if you want a practical use of all this, go look at Michael's Tie::VecArray module. that's where the vibe gets real π
π AUTHOR π
Paul Marquess β the icon, the legend, the one who did all of this β¨
π DATE π
11th December 1995. β a true vintage serve, and it still hits π
and that's the whole page bestie!! go forth and pre-process π¦π
mwah β with love from the User Contributed Perl Documentation, page Filter::cpp(3pm), shipped with perl v5.42.3, dated 2026-08-19. iykyk π«ΆπΈ
π¦ where this page comes from
- ubuntu stonking: libfilter-perl 1.65-1build1 Β· GPL-1.0-or-later OR Artistic-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms