Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

perldoc -f fileno

by Tommy (Chaplain)
on May 24, 2007 at 03:15 UTC ( [id://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

fileno FILEHANDLE
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.

--
Tommy

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-24 00:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found