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
7

DESCRIPTION

9       The three-argument form of "open" (introduced in Perl 5.6) prevents
10       subtle bugs that occur when the filename starts with funny characters
11       like '>' or '<'.  The IO::File module provides a nice object-oriented
12       interface to filehandles, which I think is more elegant anyway.
13
14         open( $fh, '>output.txt' );          # not ok
15         open( $fh, q{>}, 'output.txt );      # ok
16
17         use IO::File;
18         my $fh = IO::File->new( 'output.txt', q{>} ); # even better!
19
20       It's also more explicitly clear to define the input mode of the file,
21       as in the difference between these two:
22
23         open( $fh, 'foo.txt' );       # BAD: Reader must think what default mode is
24         open( $fh, '<', 'foo.txt' );  # GOOD: Reader can see open mode
25

NOTES

27       The only time you should use the two-argument form is when you re-open
28       STDIN, STDOUT, or STDERR.  But for now, this Policy doesn't provide
29       that loophole.
30

SEE ALSO

32       IO::Handle
33
34       IO::File
35

AUTHOR

37       Jeffrey Ryan Thalhammer <thaljef@cpan.org>
38
40       Copyright (C) 2005-2007 Jeffrey Ryan Thalhammer.  All rights reserved.
41
42       This program is free software; you can redistribute it and/or modify it
43       under the same terms as Perl itself.
44
45
46
47perl v5.8.8           Perl::Critic2:0:0P7o-l0i3c-y2:0:InputOutput::ProhibitTwoArgOpen(3)
Impressum