#!/usr/bin/perl -w
# ©oded by Gilgamesh 2003
# Cool-grep©
# Special Windows edition
use strict;
my $counter = 0;
print "Input the directory name: ";
my $dir = <STDIN>; chomp $dir;
print "Input the template to search: ";
my $pat = <STDIN>; chomp $pat;
my ($file);
opendir (DIR, $dir) || die "Error, while opening directory $dir: $!\n";
while ($file =readdir DIR)
{
next if (-d "$dir/$file");
if ( ! open (FILE, "$dir/$file"))
{
next
}
while(<FILE>)
{
if (/$pat/)
{
print "Line found in \'$file\' -- $_\n";
$counter++;
}
}
close(FILE);
}
print "$counter files were found during the search...\n";
close(DIR);
Кому интересно утилита вроде grep под вин. Я несколько урезал некоторые функции которые есть в grep - просто пример реализации подобных вещей "на коленке".
# ©oded by Gilgamesh 2003
# Cool-grep©
# Special Windows edition
use strict;
my $counter = 0;
print "Input the directory name: ";
my $dir = <STDIN>; chomp $dir;
print "Input the template to search: ";
my $pat = <STDIN>; chomp $pat;
my ($file);
opendir (DIR, $dir) || die "Error, while opening directory $dir: $!\n";
while ($file =readdir DIR)
{
next if (-d "$dir/$file");
if ( ! open (FILE, "$dir/$file"))
{
next
}
while(<FILE>)
{
if (/$pat/)
{
print "Line found in \'$file\' -- $_\n";
$counter++;
}
}
close(FILE);
}
print "$counter files were found during the search...\n";
close(DIR);
Кому интересно утилита вроде grep под вин. Я несколько урезал некоторые функции которые есть в grep - просто пример реализации подобных вещей "на коленке".