Re: Detecting filehandles
- From: Kevin Michael Vail <kevin@xxxxxxxxxx>
- Date: Sat, 29 Apr 2006 01:59:43 GMT
In article <48mdnTde3IAuLM_ZnZ2dnUVZ_s6dnZ2d@xxxxxxxxxxxx>,
"Subotai" <subotai@xxxxxxx> wrote:
Is there a way to detect if an argument you are passed in a subroutine is a
filehandle? For instance:
open(FILE, '/file');
foo(\*FILE);
foo($someotherarg);
sub foo {
$arg = shift;
#### do some check on $arg to see if it is a filehandle or a normal scalar
}
Look at the 'openhandle' function in Scalar::Util.
Also if you have an open filehandle, is there a way to see what file it is
referencing? For instance if you open the file "/foo", is there anyway to
get "/foo" from the filehandle? I know with the fileno() call you can get
the file descriptor, is there anyway you could use that to lookup that
information? I don't think there is but I want to be 100% sure.
I don't believe there is, either. It would be difficult to impossible
to implement under Unix, because a file is one thing and its name is
something else; in fact a file can have multiple names (directory
entries), so how would you choose which one is "the" file?
--
Kevin Michael Vail | a billion stars go spinning through the night,
kevin@xxxxxxxxxx | blazing high above your head.
. . . . . . . . . | But _in_ you is the presence that
. . . . . . . . | will be, when all the stars are dead.
. . . . . . . . . | (Rainer Maria Rilke)
.
- Follow-Ups:
- Re: Detecting filehandles
- From: Matt Garrish
- Re: Detecting filehandles
- References:
- Detecting filehandles
- From: Subotai
- Detecting filehandles
- Prev by Date: Re: open() function quesiton
- Next by Date: Re: Need help with grep function
- Previous by thread: Detecting filehandles
- Next by thread: Re: Detecting filehandles
- Index(es):
Relevant Pages
|