GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Perl::Critic::Policy::InputOutput::ProhibitBarewordDirHandles(3) User Contributed Perl Documentation Perl::Critic::Policy::InputOutput::ProhibitBarewordDirHandles(3)

Perl::Critic::Policy::InputOutput::ProhibitBarewordDirHandles - Write "opendir my $dh, $dirname;" instead of "opendir DH, $dirname;".

This Policy is part of the core Perl::Critic distribution.

Using bareword symbols to refer to directory handles is particularly evil because they are global, and you have no idea if that symbol already points to some other file or directory handle. You can mitigate some of that risk by "local"izing the symbol first, but that's pretty ugly. Since Perl 5.6, you can use an undefined scalar variable as a lexical reference to an anonymous file handle or directory handle. Alternatively, see the IO::Handle or IO::Dir modules for an object-oriented approach.

    opendir DH, $some_dir;            #not ok
    opendir *DH, $some_dir;           #not ok
    opendir \*DH, $some_dir;          #not ok
    opendir local *DH, $some_dir;     #not ok
    opendir $dh, $some_dir;           #ok
    opendir my $dh, $some_dir;        #ok
    opendir our $dh, $some_dir;       #ok
    opendir local $dh, $some_dir;     #ok
    my $dh = IO::Dir->new($some_dir); #ok

And Perl7 will probably drop support for bareword filehandles.

This Policy is not configurable except for the standard options.

Perl::Critic::Policy::InputOutput::ProhibitBarewordFileHandles::Perl::Critic::Policy::InputOutput::ProhibitBarewordFileHandles

IO::Handle

IO::Dir

Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>, "github.com/pali", "github.com/raforg"

Copyright (c) 2005-2011, 2021 Imaginative Software Systems. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2025-07-03 perl v5.40.2

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.