|Subject:||Suggested policy: avoid builtin glob() except for simple cases|
Most perl programmers who use the builtin glob() function are unaware that it has funny behaviour when given spaces. glob('*.c *.h') will return filenames matching *.c and then those matching *.h. (It is possible for the same filename to appear twice.) I believe this was originally a side-effect of running an external tcsh for globbing, and was kept for compatibility. In the above example this behaviour looks benign and even useful. Nobody would write a glob pattern like that unless they wanted to match two different wildcards. However, nowadays filenames with spaces in them are not uncommon. Code like the following my $dir = get_directory(); my @files = glob "$dir/*.txt"; contains a bug: it will break whenever $dir contains spaces. That is probably not what the programmer intended. To be safe you should use File::Glob::bsd_glob. I suggest a policy to forbid builtin glob and recommend bsd_glob instead. But then, there is nothing buggy or unsafe about glob('*.c'). To avoid too much nagging from perlcritic, the policy should make an exception if the argument to glob is a constant string.