加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

『perl』学习

发布时间:2020-12-16 00:09:07 所属栏目:大数据 来源:网络整理
导读:1. 目录下文件搜索 #!/usr/bin/perlfind_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($f

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);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读