Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikosvaggalis/8ea47a2c6f418f4c6d88503ad61c6273 to your computer and use it in GitHub Desktop.
Save nikosvaggalis/8ea47a2c6f418f4c6d88503ad61c6273 to your computer and use it in GitHub Desktop.
Perl "Advanced Perl Regular Expressions - The Pattern Code Expression" article on i-programmer.info
##Author:Nikos Vaggalis
##Licensed under Artistic License 1.0
##Accompanying code of the "Advanced Perl regular expressions - the pattern code express"
##article on i-programmer.info
##URL to full article: http://bit.ly/1QnpfmX
use Win32;
use Win32::API;
use Cwd;
use File::Spec::Functions;
use File::Find;
use File::Basename;
use File::Copy qw(move);
use feature 'state';
use HTML::Entities qw(decode_entities);
my $dir;
choose_dir();
print ("Enter a string to search: ") && (my $search=<STDIN>);
chomp $search;
find(\&wanted,($dir));
sub wanted {
state $count=1;
print "\n file current: ",$File::Find::name,"\n";
if (!-d $File::Find::name and
$File::Find::name=~
/(??{ $search=~s@(&\#x....;)(?{ if (defined($1))
{decode_entities($1)}})@$^R@xg; quotemeta $search})/xi
)
{
print "found file $count : ",$File::Find::name,"\n";
$count++;
}
}
sub choose_dir {
my $SHBrowseForFolder=new Win32::API('shell32.dll','SHBrowseForFolder','P','N');
my $SHGetPathFromIDList=new Win32::API('shell32.dll','SHGetPathFromIDList','NP','N');
my $display="CHOOSE starting directory...";
my $BrowseInfo=pack('LLLpLLLL',0,0,0,$display,0,0,0,0,0);
my $pidl=$SHBrowseForFolder->Call($BrowseInfo);
$dir=pack('x100');
$SHGetPathFromIDList->Call($pidl,$dir);
$dir =~ s/\0//g;
chdir $dir;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment