转载http://www.oschina.net/code/snippet_222150_7901

 

#!/usr/bin/perl
#use Cwd;
sub ExecuteAll(){
	local($dir) = @_;
	opendir(DIR,"$dir"|| die "can't open $dir");
	local @files =readdir(DIR);
	closedir(DIR);
	for $file (@files){
		next if($file=~m/\.$/ || $file =~m/\.\.$/);
		if ($file =~/\.(sh)$/i){
			system "xterm -e bash \"$dir\/$file\"";
		}
		elsif($file =~/\.(bin|run|bundle)$/i){
			system "xterm -e \"$dir\/$file\"";
		}
		elsif($file =~/\.(pl)$/i && $file != $0){
			system "xterm -e perl \"$dir\/$file\"";
		}
		elsif($file =~/\.(class)$/i){
			$file =~ s/(.*)\.(.*)/$1/;
			system "xterm -e java \"$dir\/$file\"";
		}
		elsif($file =~/\.(rpm)$/i){
			system "xterm -e rpm -ivh \"$dir\/$file\"";
		}
		elsif($file =~/\.(rb)$/i){
			system "xterm -e ruby \"$dir\/$file\"";
		}
		elsif($file =~/\.(py)$/i){
			system "xterm -e python \"$dir\/$file\"";
		}
		elsif($file =~/\.(jar)$/i){
			system "xterm -e java -jar \"$dir\/$file\"";
		}
		elsif(-d "$dir/$file"){
			ExecuteAll("$dir/$file" );
		}
	}
}
&ExecuteAll(getcwd);