Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Includes within includes

by msk_0984 (Friar)
on Dec 23, 2006 at 09:27 UTC ( [id://591431]=note: print w/replies, xml ) Need Help??


in reply to Re: Includes within includes
in thread Includes within includes

Hi

Thanx for ur replies and coming to the topic actually i am working this out in LINUX and here we are using it temporarily for a file which has around 100 include statements and again in each inlcude file there may be around 1 to 10 ranging depinding on the type of device rules file. So here its just parent and a Child level ......

Firstly we want to test it our for at leat 2 to 3 levels of includes within include files. Coming to the fastness as you said it not a big problem about it will be OK if it takes adequate amount of time.

i shall also jus give out a sample code which is presently backing up the files which are not having any inlcude statements and also recursively searching for the inlcude into the Depth........

#!/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 = <FH1>; 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 Includ +e Error: $! \n"; print CR " @main_file_cont "; close(CR); } }
here i am able to back the files with no inlcude statements and also the files which has inlcudes i am backing up the main file too and then searching and gooing into the depth . So jus check ot out and i shall be waiting for ur replies and thank you very much for ur help....
Work Hard Party Harderrr!!
Sushil Kumar

Replies are listed 'Best First'.
Re^3: Includes within includes
by throop (Chaplain) on Dec 23, 2006 at 14:02 UTC
    Are these rules files generated by a program, or have they been hand coded? If the latter, you probably want to check for single quotes around the filename too, rather than just double quotes.

    You've got my $count twice (as strict will warn you.) The value of $count isn't going to make it out of the if statement, so your $count == 0 test will always succeed.

    In your

    $main_file_line =~ /^(\s+)?include\s+"(.*)"$/
    the (\s+)? is obfusciated; \s* is much clearer and efficient.

    Are you sure you don't have any circular dependencies in your include statements? You aren't testing for them. If there is one... well, endless loops take a long time to finish. Also, how do you want to handle the case where there are overlapping dependencies? E.g, A includes B and C; B and C each include D. Do you really want D and its dependencies to be searched twice?

    throop

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 17:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found