Advertisement
nikosv

Advanced Perl regular expressions - the pattern code express

Feb 8th, 2016
646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.38 KB | None | 0 0
  1. ##Author:Nikos Vaggalis
  2. ##Licensed under Artistic License 1.0
  3. ##Accompanying code of the "Advanced Perl regular expressions - the pattern code express"
  4. ##article on i-programmer.info
  5. ##URL to full article: http://bit.ly/1QnpfmX
  6.  
  7. use Win32;
  8. use Win32::API;
  9. use Cwd;
  10. use File::Spec::Functions;
  11. use File::Find;
  12. use File::Basename;
  13. use File::Copy qw(move);
  14. use feature 'state';
  15. use HTML::Entities qw(decode_entities);
  16.  
  17. my $dir;
  18. choose_dir();
  19.  
  20. print ("Enter a string to search: ") && (my $search=<STDIN>);
  21. chomp $search;
  22.  
  23.  
  24.  
  25. find(\&wanted,($dir));
  26.  
  27.  
  28. sub wanted {
  29.     state $count=1;
  30.     print "\n file current: ",$File::Find::name,"\n";
  31.     if (!-d $File::Find::name and
  32.     $File::Find::name=~
  33.         /(??{ $search=~s@(&\#x....;)(?{ if (defined($1))
  34.             {decode_entities($1)}})@$^R@xg;  quotemeta $search})/xi
  35.              
  36.              )
  37.     {
  38.         print "found file $count : ",$File::Find::name,"\n";
  39.         $count++;
  40.     }
  41.    
  42.  
  43.  }
  44.  
  45.  
  46. sub choose_dir {
  47.     my $SHBrowseForFolder=new Win32::API('shell32.dll','SHBrowseForFolder','P','N');
  48.     my $SHGetPathFromIDList=new Win32::API('shell32.dll','SHGetPathFromIDList','NP','N');
  49.  
  50.     my $display="CHOOSE starting directory...";
  51.     my $BrowseInfo=pack('LLLpLLLL',0,0,0,$display,0,0,0,0,0);
  52.     my $pidl=$SHBrowseForFolder->Call($BrowseInfo);
  53.  
  54.     $dir=pack('x100');
  55.     $SHGetPathFromIDList->Call($pidl,$dir);
  56.  
  57.     $dir =~ s/\0//g;
  58.     chdir $dir;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement