Re: [PATCH 2/5] gitweb: Do not use bareword filehandles

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 10 May 2009, Petr Baudis wrote:
> On Sun, May 10, 2009 at 02:36:19AM +0200, Jakub Narebski wrote:

> > ---
> > Perl::Critic::Policy::InputOutput::ProhibitBarewordFileHandles
> > 
> >   Write open my $fh, q{<}, $filename; instead of open FH, q{<}, $filename;.
> > 
> >   Using bareword symbols to refer to file handles is particularly evil
> >   because they are global, and you have no idea if that symbol already
> >   points to some other file 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 filehandle.
> > 
> > See also Damian Conway's book "Perl Best Practices",
> > chapter "10.1. Filehandles" (Don't use bareword filehandles.)
> > 
> > 
> > This follows similar patch for git-send-email.perl by Bill Pemberton
> > http://permalink.gmane.org/gmane.comp.version-control.git/117886
> > 
> > CC-ed Pasky, who is responsible for code in both cases...
> 
> Yeah, the book I learnt Perl from many years ago used bareword
> filehandles (but it was an excellent textbook in most other aspects)
> so this is a custom I have to work hard to evict. ;-)
> 
> Acked-by: Petr Baudis <pasky@xxxxxxx>

Well, on one hand this is less of an issue for standalone script like
gitweb is than for library / module.  On the other hand we use indirect
filehandles everywhere else, so it is also matter of style consistency.

"Perl Best Practices" gives as an example of bad behavior which we can
get by using bareword [global] filehandles: 1) automatic closing of
other filehandle with the same name (e.g. not only you use FILE for
bareword filehandle); 2) open might fail if there exist subroutine /
constant with the same name as filehandle e.g. EXDEV (from POSIX module).

Note however that prior to Perl 5.6 it was not that easy to avoid
using bareword filehandles. Perhaps the book in question (or author of
the textbook you mention) started with earlier Perl...


P.S. Git.pm generates surprisingly small amount of perlcritic-isms,
most of whose are either matter of style, or are false positives.
-- 
Jakub Narebski
Poland
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]