Filter::m4(3pm)
β¨ NAME β¨
Filter::m4 β the M4 source filter, bestie π
π¦ SYNOPSIS π¦
use Filter::m4;
use Filter::m4 'prefix';
πΈ DESCRIPTION πΈ
Okay so here's the tea β: this source filter takes your current source file and pipes it straight through the M4 macro processor (aka m4) β but only if it's available. No cap.
And like every other source filter out there, its scope is limited to the current source file only. So every single file you want the filter to touch needs this line chillin' near the top:
use Filter::m4;
That's the vibe check. Miss it and the file just... doesn't get processed. π
π EXAMPLE π
Here's a lil baby example showing how to define an M4 macro and actually use it, because slay:
use Filter::m4;
define(`foo', `$1 =~ s/bar/baz/r')
$a = "foobar";
print "a = " . foo(`$a') . "\n";
And the output of the above example? It's giving β¨:
a = foobaz
π NOTES π
By default, M4 uses ` and ' as its quotes β iconic, but also: this is configurable using M4's changequote builtin. So you're not stuck with it, periodt.
M4 uses $1, $2, etc., to indicate arguments inside macros. And the way those clash with Perl regex syntax?? π To avoid the drama, it's recommended to use Perl's alternative forms "${1}", "${1}", etc.
Also, heads up: the following keywords in M4 and Perl are identical, which is a whole situation:
eval
format
index
mkstemp
shift
substr
So if you need such keywords in your Perl code, you've gotta pick one of these three solutions, no skips:
- Protect the keyword with M4 quotes, for example
`shift'. - Redefine the problematic M4 builtin using
defn, as outlined in section Renaming macros of the M4 info manual. - Use the
"prefix"option. This adds the prefixm4_to all M4 builtins (but not to user-defined macros) β so you'll have to usem4_shiftinstead ofshift. Lowkey genius π§
Note that use Filter::m4 'prefix'; is the only import option here, so if you're doing prefix mode, that's the whole move.
π AUTHOR π
Werner Lemberg β thank you for your service π«Ά
β DATE β
17th March 2018.
And that's a wrap, bestie π This page came to you from perl v5.42.3, dated 2026-08-19, and it lives in the Filter::m4(3pm) manual. Byeee ππ
π¦ 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