Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

perldoc -f fileno

by Tommy (Chaplain)
on May 24, 2007 at 03:15 UTC ( #617151=perlquestion: print w/replies, xml ) Need Help??

Tommy has asked for the wisdom of the Perl Monks concerning the following question:

tommy@blessed ~/
$ perldoc -f fileno

Returns the file descriptor for a filehandle, or
undefined if the filehandle is not open.
(Filehandles connected to memory objects via new
features of "open" may return undefined even though
they are open.)

...So I am really wondering if some perlio guru out there could elaborate on that last statement of the perl documentation for fileno(). What, pray tell, is it talking about?

While I am doing my own research, I still appreciate the insight my monkly bretheren may have to offer. Many thanks for the insight.


Replies are listed 'Best First'.
Re: perldoc -f fileno
by imp (Priest) on May 24, 2007 at 03:58 UTC
    You can open a filehandle that uses a scalar reference as the data source, like this:
    use strict; use warnings; my $data = "a\nb\n"; open my $fh, '<', \$data; my $fileno = fileno $fh; printf "fileno: %s\n", defined $fileno ? $fileno : '(undef)'; print for <$fh>; close $fh; $fileno = fileno $fh; printf "fileno: %s\n", defined $fileno ? $fileno : '(undef)';
Re: perldoc -f fileno
by sgifford (Prior) on May 24, 2007 at 16:27 UTC
    Somewhat more generally, fileno returns the operating system's file descriptor number for the open file. Perl will sometimes let you pretend something is a file which really isn't, as in imp's example. In that case, Perl will give you a filehandle that isn't connected to a real file. If you create such a filehandle then ask for the operating system's descriptor, there isn't really an open file, so undef is returned.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://617151]
Approved by chargrill
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2021-02-25 16:11 GMT
Find Nodes?
    Voting Booth?

    No recent polls found