If you name your constants file something with a .PL on the end, EU::MM will automatically run it for you. You could even generate your .pm directly this way.

# 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 = <DATA> ) { 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

Produces my-constants.pm

# 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

And my-constants.h

/* Generated content follows. Edit my-constants.PL instead. */ #define FOO 1 #define BAR 2 #define BAZ 3 /* End of generated my-constants.h */

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊


In reply to Re: Identical symbolic constants in XS and Perl by diotalevi
in thread Identical symbolic constants in XS and Perl by grinder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.