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
    );
  • 相关阅读:
    并查集扩展域 —— [NOI2001]食物链
    C++ P4568 [JLOI2011]飞行路线 ---- Dijkstra+分层图
    单源最短路径--Dijkstra
    链式前向星学习
    深度理解链式前向星
    「学习笔记」链式前向星
    【转】到底EJB是什么
    什么是JPA
    把nc v6的源码看懂
    用友--扩展插件要怎么做
  • 原文地址:https://www.cnblogs.com/zhumao/p/211119.html
Copyright © 2011-2022 走看看