1Perl::Critic::Policy::IUPnseperurlt:OC:uoCtnrptiurttii:bc:u:Pt:rePodohliPibecirytl:T:wDIoonAcpruugmtOeOpnuettnap(tu3it)o:n:ProhibitTwoArgOpen(3)
2
3
4

NAME

6       Perl::Critic::Policy::InputOutput::ProhibitTwoArgOpen - Write "open
7       $fh, q{<}, $filename;" instead of "open $fh, "<$filename";".
8

AFFILIATION

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

DESCRIPTION

13       The three-argument form of "open" (introduced in Perl 5.6) prevents
14       subtle bugs that occur when the filename starts with funny characters
15       like '>' or '<'.  The IO::File module provides a nice object-oriented
16       interface to filehandles, which I think is more elegant anyway.
17
18         open( $fh, '>output.txt' );          # not ok
19         open( $fh, q{>}, 'output.txt' );     # ok
20
21         use IO::File;
22         my $fh = IO::File->new( 'output.txt', q{>} ); # even better!
23
24       It's also more explicitly clear to define the input mode of the file,
25       as in the difference between these two:
26
27         open( $fh, 'foo.txt' );       # BAD: Reader must think what default mode is
28         open( $fh, '<', 'foo.txt' );  # GOOD: Reader can see open mode
29
30       This policy will not complain if the file explicitly states that it is
31       compatible with a version of perl prior to 5.6 via an include
32       statement, e.g. by having "require 5.005" in it.
33

CONFIGURATION

35       This Policy is not configurable except for the standard options.
36

NOTES

38       There are two cases in which you are forced to use the two-argument
39       form of open. When re-opening STDIN, STDOUT, or STDERR, and when doing
40       a safe pipe open, as described in perlipc.
41

SEE ALSO

43       IO::Handle
44
45       IO::File
46

AUTHOR

48       Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
49
51       Copyright (c) 2005-2011 Imaginative Software Systems.  All rights
52       reserved.
53
54       This program is free software; you can redistribute it and/or modify it
55       under the same terms as Perl itself.
56
57
58
59perl v5.16.3          Perl::Critic2:0:1P4o-l0i6c-y0:9:InputOutput::ProhibitTwoArgOpen(3)
Impressum