[EMAIL PROTECTED] wrote:
> ------------------------------------------------
> On Fri, 31 Jan 2003 10:59:17 -0500, "Jamie Risk"
> <[EMAIL PROTECTED]> wrote:
>
>> The question stems from the fact that I don't really know what
>> 'type' a file
>> handle is; and I'm also confused about what
>>    open FILEHANDLE
>> does as opposed to,
>>    open FILEHANDLE, $my_file

The first version is a strange economy. It opens the file specified
by scalar $FILEHANDLE on handle FILEHANDLE. i.e. the scalar with
the same name as the filehandle. It's the same as:

    open FILEHANDLE, $FILEHANDLE;

I believe this is a false economy, although to my knowledge
it isn't deprecated.

>>
>
> A file handle is a glob. And I believe may be passed to a subroutine
> in the following manner:
>
> subroutine_name(*FILEHANDLE);

Yes it may, but no it isn't. You mean a 'typeglob', and it isn't one of
those either. A filehandle is a filehandle, and has its own slot in the
typeglob, just like scalars, arrays and so on. The differecnce is that
there's no 'funny character' to say that you're using the filehandle
part of the typeglob. Because of this it's common to pass the entire
typeglob to functions, so that the filehandle is passed along with
everything else of the same name.

>
> However, in newer Perl a file handle may be stored to a scalar like
> any other reference, then it is just a matter of passing the scalar,
> for instance:
>
> my $FILEHANDLE;
> open($FILEHANDLE,'/path/to/file') or die "Couldn't open file for
> reading: $!";
>

This actually puts an anonymous typeglob reference in the scalar,
but since it's anonymous there's no danger that you're giving access
to other variables of the same name.

>
> ...then later...
>
> subroutine_name($FILEHANDLE) will work...though this may not be
> advisable.

On the contrary, that's fine. You can also pass a reference to a named
typeglob like this:

    subroutine_name(\*STDOUT);

but as far as I can think there is no advantage over simply passing the
typeglob itself. Maybe somebody can tell me why I should want
to do this?

> I don't believe your first type of open will work, the second opens
> the specified file for reading.  Have a look to:

Yes it will! But I've already explained that :)

> perldoc perlopentut
> and perldoc -f open

...and

    perldoc -q "How can I pass"

Cheers,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to