1. 目录下文件搜索
#!/usr/bin/perl
&find_fileindir("/usr/local/apache/htdocs");
sub find_fileindir(){
local($dir) = @_;
opendir(DIR,"$dir"|| die "can't open this $dir");
local @files =readdir(DIR);
closedir(DIR);
for $file (@files){
next if($file=~m/\.$/ || $file =~m/\.\.$/);
if ($file =~/\.(html|htm|shtml)$/i){
print "$dir\/$file \n";
}
elsif(-d "$dir/$file"){
find_fileindir("$dir/$file" );
}
}
}
2. C调用perl,或者,http://www.hailongchang.org/index.php/archives/365
要调用特定的 Perl 函数,可使用 call_argv 函数。该函数调用一个指定的函数,包括给该 Perl 函数提供任何参数的能力。
#include <EXTERN.h>
#include <perl.h>
static PerlInterpreter *my_perl;
int main(int argc, char **argv, char **env)
{
char *print_args[] = {"This","is","a","list","of","printable","items","\n",NULL};
my_perl = perl_alloc();
perl_construct(my_perl);
perl_parse(my_perl, NULL, argc, argv, NULL);
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
call_argv("printwrap", G_DISCARD, print_args);
perl_destruct(my_perl);
perl_free(my_perl);
}