Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

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
Node Status?
node history
Node Type: perlquestion [id://617151]
Approved by chargrill
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2018-07-16 20:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (349 votes). Check out past polls.

    Notices?