Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id: 41872
Status: new
Priority: 0/
Queue: Perl-Critic

People
Owner: Nobody in particular
Requestors: EDAVIS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.092
Fixed in: (no value)



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.