H2PH(1)
๐ NAME ๐
h2ph โ bestie, it converts .h C header files into .ph Perl header files, and honestly? iconic behavior.
So like, this is from the Perl Programmers Reference Guide, section 1, and the whole point of it is turning your crusty old C headers into something Perl can vibe with. ๐ฆ
โจ SYNOPSIS โจ
h2ph [-d destination directory] [-r | -a] [-l] [-h] [-e] [-D] [-Q]
[headerfiles]
๐ธ DESCRIPTION ๐ธ
Okay so h2ph takes any C header files you throw at it and converts them into the corresponding Perl header file format. The easiest way to run it is while you're sitting in /usr/include, like:
cd /usr/include; h2ph * sys/*
or, if you're feeling extra:
cd /usr/include; h2ph * sys/* arpa/* netinet/*
or, the full main-character move:
cd /usr/include; h2ph -r -l .
The output files get dropped into the hierarchy rooted at Perl's architecture dependent library directory. Not vibing with that location? Just say so with a -d switch and pick your own hierarchy, no cap.
And if you run it with no arguments at all, it just filters standard input to standard output. Simple. Clean. A little mysterious. ๐
๐ OPTIONS ๐
-d destination_dirโ drop the resulting.phfiles underneath destination_dir instead of underneath the default Perl library location ($Config{'installsitearch'}). You're the boss of your own filesystem, bestie.-rโ run recursively! If any of headerfiles are directories, thenh2phgets run on all the files in those directories (and their subdirectories, etc., etc., all the way down ๐). Heads up:-rand-aare mutually exclusive โ they cannot both be your moment.-aโ run automagically โจ convert headerfiles, plus any.hfiles which they include. This one searches for.hfiles in all the directories your C compiler ordinarily uses. Also,-aand-rare mutually exclusive, so pick a lane.-lโ symbolic links get replicated in the destination directory. If you don't pass-l, then links are just skipped over. Gone. Ignored. ๐-hโ put 'hints' in the.phfiles, which helps when you're hunting down problems withh2ph. So in those cases where you genuinely need a.phfile that contains syntax errors, instead of the cryptic
[ some error condition ] at (eval mmm) line nnn
you'll see the slightly more helpful
[ some error condition ] at filename.ph line nnn
Gorgeous, right? Only catch: the .ph files almost double in size when you build them with -h. Worth it for the clarity though, imo.
-eโ if an error pops up during conversion, the output file gets removed and a warning gets emitted instead of the whole conversion terminating immediately. Graceful failure, we love to see it. ๐ซถ-Dโ include the code from the.hfile as a comment inside the.phfile. This is primarily used for debuggingh2phitself. Detective mode. ๐-Qโ 'Quiet' mode ๐ง don't print out the names of the files being converted. Sometimes silence really is the vibe.
๐ ENVIRONMENT ๐
No environment variables are used. Literally none. Zero. Nada. The env is not the main character here. ๐
๐ FILES ๐
/usr/include/*.h
/usr/include/sys/*.h
etc. (you get the picture, bestie).
โญ AUTHOR โญ
Larry Wall. The icon. The legend. ๐
๐ฅ SEE ALSO ๐ฅ
๐ DIAGNOSTICS ๐
The usual warnings if it can't read or write the files involved. Like, standard stuff โ nothing dramatic, just the classic "can't touch this file" energy.
๐ BUGS ๐
Okay, deep breath, because there are a few things you should know, fr fr:
- It doesn't construct the
%sizeofarray for you. You're on your own for that one, bestie. ๐ญ - It doesn't handle all C constructs, but it does attempt to isolate definitions inside evals so that you can still get at the definitions that it can translate. Partial credit, slay.
- It's only intended as a rough tool. You may need to dicker with the files produced. Yes, dicker. That's the word. You'll be fiddling with these files, ngl.
- You have to run this program by hand โ it's not run as part of the Perl installation. So it's not automatic, it's a whole manual thing. ๐
- It doesn't handle complicated expressions built piecemeal, a la:
enum {
FIRST_VALUE,
SECOND_VALUE,
#ifdef ABC
THIRD_VALUE
#endif
};
- It doesn't necessarily locate all of your C compiler's internally-defined symbols. Some of them are just gonna be out there, living their truth, unlocated.
Fair warning bestie: this is a rough tool by design, so don't expect perfection โ dicker with the output and you'll be fine. ๐
Okay that's the whole page, mwah! This gorgeous little manual dropped as perl v5.42.3, dated 2026-11-03 โ go forth and convert those headers, bestie ๐โจ
๐ฆ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms