English 中文(简体)
Find:File preprocess
原标题:Find::File preprocess
  • 时间:2011-04-08 19:16:58
  •  标签:
  • perl

I m trying to specify a directory, and recursively find every file in the sub-directories. After find chdir s into a directory, I want to do some processing before find reads the files. Here is a simplified snippet that demonstrates the problem. It doesn t recurse into the subdirectories, but it looks like it should. I can verify that the sub-dirs and files exist because if I call find without the preprocess key then I get the listing. I haven t been using Perl for that long so I m kind of stumped.


find({
  wanted => &wanted,
  preprocess => &preprocess
}, "/home/nelson/invoices/");


# function definitions

sub wanted {
  print "Calling wanted...
";
  print "	" . $File::Find::name . "
";
}

sub preprocess{
  print "Calling preprocess...
";
  print "	" . $File::Find::dir . "
";
}

这里是产出。


Calling wanted...
        /home/nelson/invoices
Calling preprocess...
        /home/nelson/invoices
Calling wanted...
        /home/nelson/invoices/1
最佳回答

预计preprocess功能将退回一份(可能修改的)项目清单作进一步审查。 举例来说,请在<代码>前<>/代码>末尾添加@_;,以退回未经修改的论点。 您可以做一些事情,例如<代码>grep{_美元-!~ /pattern/}@_,以过滤不想要的物品,等等。

问题回答

暂无回答




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签