- 论坛徽章:
- 6
|
改一波,建议用use strict; 啦 - #!/usr/bin/perl -w
- # open OUT1,'+>E:/3.txt';
- printf"write the path you want to search files:";
- $searchdir=<STDIN>;
- chomp $searchdir;
- printf "Input search string, one per line, end with a single '.' :\n";
- $searchstr = +{};
- while ($line = <STDIN>) {
- $line =~ s{^\s+ | \s+$}{}gmix;
- next if not $line;
- last if $line eq '.';
- $searchstr->{$line} = 1
- }
- # $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 ! ";
- # $lines=1;
- while (defined($line=<FileHandle>)) {
- $line =~ s{^\s+ | \s+$}{}gmix;
- next if not $line;
- if (exists $searchstr->{$line}) {
- $file = "$line.txt";
- if (-f $file) {
- print "Found [$line], file [$file] alreay created, no need to create again.\n";
- }
- else {
- open OUT1, ">$file";
- close(OUT1);
- print "Found [$line], file [$file] created.\n";
- }
- }
- # $back=index($line,$searchstr);
- # if ( $back != -1 ) {
- # # print OUT1 "$line";
- # }
- # $lines=$lines+1;
- }
- close(FileHandle);
- }
- # close(FileHandle);
- }
- # close(OUT1);
- closedir(DIRHANDLE);
复制代码 output sample:- write the path you want to search files:TEXT
- Input search string, one per line, end with a single '.' :
- beijing
- wuhan
- .
- TEXT/. is a directory!
- TEXT/.. is a directory!
- Found [wuhan], file [wuhan.txt] created.
- Found [beijing], file [beijing.txt] created.
- Found [wuhan], file [wuhan.txt] alreay created, no need to create again.
复制代码 |
|