Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Inlining method/function calls?

by Zaxo (Archbishop)
on Jul 26, 2003 at 23:26 UTC ( #278159=note: print w/replies, xml ) Need Help??


in reply to Inlining method/function calls?

There are two cases in perl which sort of correspond to inlining.

One is the folding of constant functions in the compiler's optimization phase. That doesn't give you much direct control, but you can take pains to make perl notice the opportunity. Empty prototypes and constant.pm help there.

The other, mentioned by adrianh, is to invoke the C preprocessor with the -P flag. An example,

#!/usr/bin/perl -P #define Foo(a) {\ local $, = " ";\ print "defined: ", a, $/;\ } my ($c, $d, @e, %f) = ('c','d',qw/all in e/); @f{qw/all in f/} = @e; Foo($c) Foo($d) Foo(@e) Foo(%f)

After Compline,
Zaxo

Replies are listed 'Best First'.
Re2: Inlining method/function calls?
by dragonchild (Archbishop) on Jul 28, 2003 at 15:54 UTC
    That is very cool! Right after I ran that snippet, I looked in 3rd Camel to see what it says, but it's quite sparse in what you can do. What is possible? Where could I go for more info, especially examples ...

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      The -P flag turns loose the C preprocessor on your source before perl ever sees it. Its behavior is determined by the C standard, at least for the portable parts. The handiest source of information is probably a C primer.

      In short, the C preprocessor makes direct textual substitution. with some logic available. I've never needed it for perl, but potentially useful constructs include,

      • #include "filename" - inclusion of source from another file.
      • #define foo some string or other - substitution macro definition
      • #if, #elseif, #else, and friends allow for conditional inclusion of source.
      None of this is really necessary to perl.

      After Compline,
      Zaxo

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://278159]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2021-05-15 02:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (150 votes). Check out past polls.

    Notices?