#!/usr/bin/perl use strict; my $first_path = "/opt/netcool/etc/test.rules"; &srch_include($first_path); my ($incl_full_path , $dir_path, $file_name) ; sub srch_include { my ($main_path) = @_ ; print " First Sub Path : $main_path \n"; open( FH1, "$main_path") or die " Sub1 Error: $! \n "; my @main_file_cont = ; my $count = 0; foreach my $main_file_line ( @main_file_cont ) { if( $main_file_line =~ /^(\s+)?include\s+"(.*)"$/) { my $count++; $incl_full_path = $2 ; print " Inlcudes :: $incl_full_path \n "; $incl_full_path =~ /(.*\/)(.*)/; $dir_path = $1 ; $file_name = $2; print " Dir : $dir_path File : $file_name \n "; system ("mkdir -p /root/msk/$dir_path"); sleep 2 ; open(CR, ">/root/msk/$incl_full_path") or die " Main File Error: $! \n"; print CR " @main_file_cont "; close(CR); &srch_include($incl_full_path); } } if($count == 0 ) { #print " $incl_full_path has No includes and lookup \n "; $incl_full_path =~ /(.*\/)(.*)/; $dir_path = $1 ; $file_name = $2; #print " Dir : $dir_path File : $file_name \n " system ("mkdir -p /root/msk/$dir_path"); sleep 2 ; open(CR, ">/root/msk/$incl_full_path") or die " No Include Error: $! \n"; print CR " @main_file_cont "; close(CR); } }