# my-constants.PL open my $pm, ">", "my-constants.pm" or die "Can't open my-constants.pm: $!"; open my $h, ">", "my-constants.h" or die "Can't open my-constants.h: $!"; print { $pm } "# Generated content follows. Edit $0 instead.\n" or die "Can't write to my-constants.pm: $!"; print { $h } "/* Generated content follows. Edit $0 instead. */\n" or die "Can't write to my-constants.h: $!"; while ( my $const = ) { chomp $const; my ( $name, $val ) = split ' ', $const, 2; print { $pm } "use constant '$name' => $const;\n" or die "Can't write to my-constants.pm: $!"; print { $h } "#define $name $const\n" or die "Can't write to my-constants.h: $!"; } print { $pm } "1; # End of generated my-constants.pm\n" or die "Can't write to my-constants.pm: $!"; print { $h } "/* End of generated my-constants.h */\n" or die "Can't write to my-constants.h: $!"; close $pm or die "Can't flush my-constants.pm: $!"; close $h or die "Can't flush my-constants.h: $!"; __DATA__ FOO 1 BAR 2 BAZ 3 #### # Generated content follows. Edit my-constants.PL instead. use constant 'FOO' => 1; use constant 'BAR' => 2; use constant 'BAZ' => 3'; 1; # End of generated my-constants.pm #### /* Generated content follows. Edit my-constants.PL instead. */ #define FOO 1 #define BAR 2 #define BAZ 3 /* End of generated my-constants.h */