Perl File::Find::Rule::LibMagic:保留未定义值的选项可以吗?
保留未定义值的选项(在本例中为“maxdepth”)可以吗 或者我应该这样写:Perl File::Find::Rule::LibMagic:保留未定义值的选项可以吗?,perl,undefined,options,optional-parameters,file-find,Perl,Undefined,Options,Optional Parameters,File Find,保留未定义值的选项(在本例中为“maxdepth”)可以吗 或者我应该这样写: if ( defined $max_depth ) { @dbs = find( file => magic => 'SQLite*', maxdepth => $max_depth, in => $dir ); } else { @dbs = find( file => magic => 'SQLite*', in => $dir ); } 好吗?它可能不
if ( defined $max_depth ) {
@dbs = find( file => magic => 'SQLite*', maxdepth => $max_depth, in => $dir );
} else {
@dbs = find( file => magic => 'SQLite*', in => $dir );
}
好吗?它可能不会混淆File::Find::Rule
$ perl -MFile::Find::Rule -le " print for File::Find::Rule->maxdepth(undef)->in( q/tope/ ) "
tope
tope/a
tope/b
tope/c
tope/c/0
tope/c/1
tope/c/2
$ perl -MFile::Find::Rule -le " print for File::Find::Rule->maxdepth(1)->in( q/tope/ ) "
tope
tope/a
tope/b
tope/c
$ perl -MFile::Find::Rule -le " print for File::Find::Rule->maxdepth(-1)->in( q/tope/ ) "
tope
$ perl -MFile::Find::Rule -le " print for File::Find::Rule->maxdepth(2)->in( q/tope/ ) "
tope
tope/a
tope/b
tope/c
tope/c/0
tope/c/1
tope/c/2
$ pmvers File::Find::Rule
0.33
通过使用
undef
作为其值的变量,将maxdepth
设置为undef
应该没有问题。Perl中的每个变量都以unde
值开始
更多细节
延伸。中的函数以以下内容开头:
sub find {
my $object = __PACKAGE__->new();
函数返回:
bless {
rules => [],
subs => {},
iterator => [],
extras => {},
maxdepth => undef,
mindepth => undef,
}, $class;
请注意,
maxdepth
默认设置为undef
此问题是关于。这应该在标题中显示得更清楚。我在标题中添加了File::Find::Rule::LibMagic
。但我的兴趣更为广泛——但可能每个模块的兴趣不同。
bless {
rules => [],
subs => {},
iterator => [],
extras => {},
maxdepth => undef,
mindepth => undef,
}, $class;