?? searchfile.pl
字號:
#! D:/Perl/bin/perl -w
use strict;
require filedir_misc;
my $debug = $ARGV[1];
my ($findAmount, $stopIndex) = (0, 105);
sub dirParse()
{
my $dirName = shift;
return 0 if ($dirName =~ m/cvs/i);
return -1;
}
sub searchInFile()
{
my ($fileName, $strToFind) = @_;
my ($line, $lineNum, $ret);
&strToRegEx(\$strToFind);
$lineNum = 0;
$ret = -1;
open(CURFILE, $fileName) || die $!;
while ($line = <CURFILE>) {
++$lineNum;
#print "line--" . $lineNum . "\n" if ($debug);
if ($line =~ m/$strToFind/i) {
print "$strToFind\n" if ($debug);
$ret = $lineNum;
last;
}
}
close(CURFILE);
return $ret;
}
sub fileHandler()
{
my ($fileName, $dirParseValue) = @_;
my ($strFindRet, $strToFind);
# here is file_name compare only
# if (-f $fileName and $fileName =~ m /JkUDP\.[c|h]/i) {
# print "find file --- $fileName\n";
# exit() if (0 == $stopIndex || ++$findAmount >= $stopIndex);
# }
$strToFind = 'JkJabwtLocDevIsPowerOn';
if (-f $fileName and $fileName =~ m /.*\.[c|h]/i) {
#print "find file --- $fileName\n" if ($debug);
$strFindRet = &searchInFile($fileName, $strToFind);
if (0 < $strFindRet) {
print "--------$findAmount\n";
print "$strToFind\n";
print "line: $strFindRet - $fileName\n";
exit(0) if (0 == $stopIndex || ++$findAmount >= $stopIndex);
}
}
}
sub dirHandler()
{
my ($curDir, $dirParseValue) = @_;
#print "handling folder ---------------------------- $curDir\n";
}
sub main
{
if (! $ARGV[0] or !-e $ARGV[0]) {
print "usage:\n\t perl \"this.pl\" directory [dbg].\n";
return 0;
}
&handleSingleDir($ARGV[0], *dirParse, 1, *dirHandler, *fileHandler, -1) if (-d $ARGV[0]);
}
&main();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -