Don't use single-word all-upper-case package names.
Your example isn't the only way that you'll run into problems with such poor package names. Don't follow the bad examples of CGI.pm and CPAN.pm (which are badly named for more than just this reason, as anyone who ever tried to talk about "CGI" or "CPAN" knows; Net::CGI and Net::CPAN would be much better).
For that matter, don't use bareword file handles. Your example isn't the only way you'll run into problems using those.
Now, you can make an exception for STDIN, STDOUT, STDERR, and DATA. But if you really write "package STDIN;", then you deserve all of the grief you get.
Below are some other things you shouldn't do. Perl has a lot of DWIM features and DWIM always implies ambiguity and the possibility that Perl will misinterpet what you thought you meant.
Don't use single-word, all-lower-case subroutine names. If you do, then you can reduce your risk by either calling them like &mysub(...) or by putting them into a module (and then import them, use the full name with package name in front, or use OO).
Note that writing &mysub(...) will likely get you yelled at by people who think it is "bad style" or "looks like Perl 4" or some other bogus reason [such as confusing &mysub(...) with &mysub;].
And if you make the mistake of using a prototype, then you probably shouldn't be writing &myprototypedsub(...) but that's okay because using a prototype means you should put the function into a module anyway (but OO isn't an option in this case) -- and you should include an apology in the module's POD.
Similarly, don't use single-word, all-upper-case subroutine names or single-word all-lower-case package names.
In fact, don't use single-word package names. Make sure all of your package names contain :: (with exceptions for "main" or other package names that you don't get to pick).
Don't leave off parentheses when calling a function as part of an expression. If you use an assignment as part of an expression, put parens around it. If you use bit-wise operators, remember that their precedence just doesn't make sense and so put in explicit parens inside and out. Don't use here-docs; they break on invisible spaces (trailing spaces) or if you reindent. Don't use unless, it is confusing (even though it doesn't seem like it at first) and isn't any clearer (even if it seems so at first). use vars not our (as discussed in other threads). Don't use source filter modules. Use strict and (at least during development) enable warnings. etc. (:
- tye
Updated: Moved a misplaced sentence.
In reply to Re: Bad news for IO::Handle magic (SWYM or sink)
by tye
in thread Bad news for IO::Handle magic
by Stevie-O
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |