zoukankan      html  css  js  c++  java
  • 在指定文件夹中的文件中查找包含指定字符的行(这个小东西不错[Perl]) zhumao

    #!/usr/bin/perl -w
    printf"write the path you want to search files:";
    $searchdir=<STDIN
    >;
    chomp $searchdir
    ;
    printf "Input search string:"
    ;
    $searchstr=<STDIN
    >;
    chomp $searchstr
    ;
    opendir(DIRHANDLE,$searchdir) || die "Cann't open $searchdir !"
    ;
    while(
    $file=readdir DIRHANDLE
    ) {
            if (-
    d "$searchdir/$file"
    ) {
                    
    printf "$searchdir/$file is a directory!\n"
    ;
            } else {
                    
    open(FileHandle, "$searchdir/$file") || die "cann't open $searchdir/$file !\n"
    ;
                    
    $lines=1
    ;
                    while (
    defined($line=<FileHandle
    >)) {
                            
    $back=index($line,$searchstr
    );
                            if (
    $back != -1
    ) {
                                    print
    "$file:$lines:$line"
    ;
                            }
                    
    $lines=$lines+1
    ;
                    }
            }
            
    close(FileHandle
    );
    }
    closedir(DIRHANDLE
    );
  • 相关阅读:
    return, break, continue
    equals 与 ==
    过滤器
    通过域名区分虚拟主机
    通过端口区分不同虚拟机
    Nginx实现反向代理
    Nginx安装
    poj2387 Til the Cows Come Home(Dijkstra)
    hdoj2544 最短路(Dijkstra || Floyd || SPFA)
    最小生成树
  • 原文地址:https://www.cnblogs.com/zhumao/p/211119.html
Copyright © 2011-2022 走看看