5 use Filter::Util::Exec ;
14 if ($^O eq 'MSWin32') {
19 ($cpp) = $Config{cppstdin} =~ /^(\S+)/;
23 croak ("Cannot find cpp\n")
26 # Check if cpp is installed
29 foreach my $dir (split($sep, $ENV{PATH}), '')
38 croak "Cannot find cpp\n"
44 my($self, @args) = @_ ;
46 #require "Filter/exec.pm" ;
48 if ($^O eq 'MSWin32') {
49 Filter::Util::Exec::filter_add ($self, 'cmd', '/c',
53 Filter::Util::Exec::filter_add ($self, 'sh', '-c',
54 "$Config{'cppstdin'} $Config{'cppminus'} 2>/dev/null") ;
63 Filter::cpp - cpp source filter
71 This source filter pipes the current source file through the C
72 pre-processor (cpp) if it is available.
74 As with all source filters its scope is limited to the current source
75 file only. Every file you want to be processed by the filter must have a
81 Here is an example script which uses the filter:
89 print "Hello FRED\n" ;
91 print "Where is FRED\n" ;
94 And here is what it will output:
99 This example below, provided by Michael G Schwern, shows a clever way
100 to get Perl to use a C pre-processor macro when the Filter::cpp module
101 is available, or to use a Perl sub when it is not.
103 # use Filter::cpp if we can.
104 BEGIN { eval 'use Filter::cpp' }
109 #define PRINT($string) \
115 Look at Michael's Tie::VecArray module for a practical use.