1. Perl
  2. builtin functions
  3. here

fileno function - get file descriptor

To get the file descriptor , use the fileno function . In the argument, specify the open file handle.

$ret = fileno $fh;

A file descriptor is an identifier used by the OS to identify files and standard I/O. This is an integer value.


This is an example to get the file descriptor using the fileno function.

use strict;
use warnings;

# Get filename from command line arguments
my $file = shift;

# Open file
open(my $fh, '<', 'file)
  or die "Can't open file $file:$!";

# Get file descriptor
my $fileno = fileno $fh;

# output
print "$fileno\n";

Output result


Related Informatrion