Advertisement
cd62131

File::Find Using find2perl

Jul 7th, 2017
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.83 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use utf8;
  5. use open qw|:std :encoding(utf8)|;
  6. use File::Find;
  7. use Encode;
  8.  
  9. use vars qw/*name *dir *prune/;
  10. *name   = *File::Find::name;
  11. *dir    = *File::Find::dir;
  12. *prune  = *File::Find::prune;
  13.  
  14. sub wanted;
  15.  
  16. my $f1 = '/tmp/test.txt';
  17. my $f2 = '/tmp/test2.txt';
  18.  
  19. open my $in, '<', $f1 or die $!;
  20. open my $out, '>', $f2 or die $!;
  21.  
  22. my $before = select($out);
  23. File::Find::find({ wanted => \&wanted },
  24.   map { chomp; </home/$_/work/*/new/> } <$in>);
  25. select($before);
  26.  
  27. close $in;
  28. close $out;
  29. exit;
  30.  
  31. sub wanted {
  32.   my ($dev,$ino,$mode,$nlink,$uid,$gid);
  33.  
  34.   $_ = Encode::decode('utf-8', $_);
  35.   (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
  36.   -f _ &&
  37.   (int(-M _) > 90) &&
  38.   ! /(?:\p{Hiragana}|\p{Katakana}|\p{Han})/s
  39.   && print Encode::encode('utf-8', $name)."\n";
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement