The program needs to know a magical system-dependent constant called FIBMAP that is defined in the C include file <linux/fs.h>. It assumes that the current directory contains a file, fibmap.ph, which will define $FIBMAP with the appropriate value. But if fibmap.ph does not exist, then the program creates it with the correct value.

Please don't ask what this program was for.

unless (eval {require "fibmap.ph"}) { open C, "> fibmap.c" or die "Couldn't write configurator: $!; aborti +ng"; print C while <DATA>; close C; system("cc -o fibmap fibmap.c") == 0 or die "Couldn't run C compiler +.\n"; system("./fibmap > fibmap.ph") == 0 or die "Couldn't run configurato +r.\n"; unless (eval {require "fibmap.ph"}) { die "Couldn't load configurator: $@.\n"; } unlink "fibmap", "fibmap.c"; } print "Configurator ran OK; FIBMAP is $FIBMAP\n"; # ... # much code omitted here # ... __DATA__ #include <stdio.h> #include <linux/fs.h> int main(void) { printf("$FIBMAP = %d;\n1;\n", FIBMAP); return 0; }

Replies are listed 'Best First'.
Re (tilly) 1: Run-time generation of magic constant
by tilly (Archbishop) on Nov 23, 2000 at 01:39 UTC
    Wouldn't Inline be a natural solution for this?
      Yes, very much so. But Inline did not exist at the time this program was written (2 November 1999.)