Thursday, April 22, 2010

Automatically include many file from many directory

In case you write a perl program to include a require with lot of file here is a small program for that.

#!/usr/bin/perl
use strict;
use warnings;
&putAllIncludeFiles;
sub putAllIncludeFiles{
        my @thefiles=readAllFilesFromDirectories("/home/tullas/lesson/framework/lib","/home/tullas/lesson/framework/conf");
        my $f;
        foreach $f (@thefiles){
                require $f;
        }
}
sub readAllFilesFromDirectories{
   my $filename;
   my @filenames;
   foreach (@_) {
        opendir ( DIR, $_ ) || die "Error in opening dir $_\n";
        while( ($filename = readdir(DIR))){
                unless ( ($filename eq ".") || ($filename eq "..") ){
                        #print("$filename\n");
                        push @filenames,$_ . "/" . $filename;
                        $filename = "";
                }
        }
   }
   return @filenames;
   closedir(DIR);
}

No comments: