Re: why don't filehandles have punctuation before their name?
by Yohimbe (Pilgrim) on Apr 24, 2001 at 03:19 UTC
|
They can have punctuation
use FileHandle;
$fh = new FileHandle;
if ($fh->open("< file")) {
print <$fh>;
$fh->close;
}
File handles are just a scalar, IIRC, and the uppercasing is just a convention, a holdover from the other languages from whence it came.
--
Jay "Yohimbe" Thorne, alpha geek for UserFriendly | [reply] [Watch: Dir/Any] [d/l] |
|
sub myprint {
my($fh) = @_;
print $fh "Hello world.\n";
}
myprint \*STDOUT;
The FileHandle and IO::Handle modules make it more convenient to use arbitrary handles, because they hide the reference-to-glob syntax. | [reply] [Watch: Dir/Any] [d/l] |
|
Filehandles are uppercased so that the introduction of new perl keywords (which are always lowercased) do not break existing Perl scripts. Larry has endorsed this convention.
It seems to me, however, that new keywords could still break existing scripts if those scripts included subroutines with the same names as the keywords. So to be consistent we ought to name our subroutines in all uppercase as well, or at least throw in a few uppercase letters in our subroutine names.
| [reply] [Watch: Dir/Any] |
|
Perhaps you didn't notice the addition of BEGIN, END, CHECK, DESTROY, and INIT, etc. (: In fact, I think you should name subroutines with mixed case and should avoid the bareword-as-filehandle syntax. The bareword-as-filehandle syntax caused lots of problem even way back in Perl4. It is nice to have an alternative to it in Perl5.
-
tye
(but my friends call me "Tye")
| [reply] [Watch: Dir/Any] |
|
|
|
So to be consistent we ought to name our subroutines in all uppercase as well, or at least throw in a few uppercase letters in our subroutine names.
I prefer to include at least one _. As far as I know, no built-in functions contain underscores, and probably never will.
| [reply] [Watch: Dir/Any] |
Re: why don't filehandles have punctuation before their name?
by turnstep (Parson) on Apr 24, 2001 at 04:12 UTC
|
They could have....and don't forget directory handles
as well. Some say that Larry just ran out of symbols...
| [reply] [Watch: Dir/Any] |
Re: why don't filehandles have punctuation before their name?
by clintp (Curate) on Apr 24, 2001 at 04:34 UTC
|
Consider the fact that in older dialects of perl (Perl 4 and such)
that the parser can generally guess when something is supposed to
be a filehandle and when it's not. (First argument of open, first
argument to flock, close, etc...).
(Remember too that functions used to have mandatory ()'s and &'s!
So the barewords weren't so ambiguous then...)
It only begins to get tricky and nasty when you have indirect
filehandles and use <> for globbing. | [reply] [Watch: Dir/Any] |