Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

i am having a file in all directories names as include.cfg
inside this file i am havinf a number of include statements like
#include "../comm.cfg"
#include "../ext.frg"
#include "../mem.cmd"
i have changed my script, which uses this file in such a way that i need to modify my file so that now it looks like this

#ifdef SYM
#include "$INCLUDE_DIR/ext.frg"
#else
#include "../include/ext.frg"
#endif
#ifdef SYM
#include "$INCLUDE_DIR/mem.cmd"
#else
#include "../include/mem.cmd"
#endif
this code is to be added for each include statements in the file. can any one help me with this how can i do. i am not a expert of perl, just learning things.
  • Comment on modify the include files depending up on instructions in it

Replies are listed 'Best First'.
Re: modify the include files depending up on instructions in it
by perlsen (Chaplain) on Mar 17, 2005 at 08:56 UTC

    Hi just try this below coding

    input: ********* #include "../comm.cfg" #include "../ext.frg" #include "../mem.cmd" $str=qq{\#ifdef SYM \#include "$INCLUDE_DIR/ext.frg" \#else \#include "../include/ext.frg" \#endif \#ifdef SYM \#include "$INCLUDE_DIR/mem.cmd" \#else \#include "../include/mem.cmd" \#endif}; undef $/; open(READ, "< input.pl") ; $string = <READ>; close(READ); $string =~ s#(\#include.+?\n)#${str}\n$1#gsi; open(OUT, "> output.pl") ; print OUT $string; #output: #******** #ifdef SYM #include "/ext.frg" #else #include "../include/ext.frg" #endif #ifdef SYM #include "/mem.cmd" #else #include "../include/mem.cmd" #endif #include "../comm.cfg" #ifdef SYM #include "/ext.frg" #else #include "../include/ext.frg" #endif #ifdef SYM #include "/mem.cmd" #else #include "../include/mem.cmd" #endif #include "../ext.frg" #ifdef SYM #include "/ext.frg" #else #include "../include/ext.frg" #endif #ifdef SYM #include "/mem.cmd" #else #include "../include/mem.cmd" #endif #include "../mem.cmd"