in reply to Re^4: The Case for Macros in Perl
in thread The Case for Macros in Perl
Way back, in perl4, there was (from perl.man)
which was dropped (in favour of source filters, I guess). But hey, you can still run your code through cpp:-Idirectory may be used in conjunction with -P to tell the C prep +rocessor where to look for include files. By default /usr/incl +ude and /usr/lib/perl are searched. -P causes your script to be run through the C preprocessor + before compilation by perl. (Since both comments and cpp di +rectives begin with the # character, you should avoid starting +comments with any words recognized by the C preprocessor such +as "if", "else" or "define".)
#define ADD(x,y) x + y my $r = ADD( getPfromSomewhere(), getQfromSomewhere() ); ... my $s = ADD( geta(), getb() );
# 1 "macro.pl" # 1 "<command-line>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 30 "/usr/include/stdc-predef.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/predefs.h" 1 3 4 # 31 "/usr/include/stdc-predef.h" 2 3 4 # 1 "<command-line>" 2 # 1 "macro.pl" my $r = getPfromSomewhere() + getQfromSomewhere(); ... my $s = geta() + getb();
"can you tell me the way to Tipperary?" - "well, I wouldn't start from here..."
;-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: The Case for Macros in Perl
by BrowserUk (Patriarch) on Sep 15, 2014 at 11:15 UTC |