Is it OK to keep options with undefined values (in this case 'maxdepth')?
#!/usr/bin/env perl
use warnings;
use 5.012;
use File::Find::Rule::LibMagic qw(find);
use Getopt::Long qw(GetOptions);
my $max_depth;
GetOptions ( 'max-depth=i' => \$max_depth );
my $dir = shift;
my @dbs = find( file => magic => 'SQLite*', maxdepth => $max_depth, in => $dir );
say for @dbs;
Or should I write it like this:
if ( defined $max_depth ) {
@dbs = find( file => magic => 'SQLite*', maxdepth => $max_depth, in => $dir );
} else {
@dbs = find( file => magic => 'SQLite*', in => $dir );
}
There should be no problem in having
maxdepthset toundefby using a variable withundefas its value. Every variable in Perl starts out with theundefvalue.More Details
File::Find::Rule::LibMagicextendsFile::Find::Rule. Thefindfunction inFile::Find::Rulestarts with:The
newfunctions returns:Note that
maxdepthby default is set toundef.