- Perl Basics
- Perl - Home
- Perl - Introduction
- Perl - Environment
- Perl - Syntax Overview
- Perl - Data Types
- Perl - Variables
- Perl - Scalars
- Perl - Arrays
- Perl - Hashes
- Perl - IF...ELSE
- Perl - Loops
- Perl - Operators
- Perl - Date & Time
- Perl - Subroutines
- Perl - References
- Perl - Formats
- Perl - File I/O
- Perl - Directories
- Perl - Error Handling
- Perl - Special Variables
- Perl - Coding Standard
- Perl - Regular Expressions
- Perl - Sending Email
- Perl Advanced
- Perl - Socket Programming
- Perl - Object Oriented
- Perl - Database Access
- Perl - CGI Programming
- Perl - Packages & Modules
- Perl - Process Management
- Perl - Embedded Documentation
- Perl - Functions References
- Perl Useful Resources
- Perl - Questions and Answers
- Perl - Quick Guide
- Perl - Useful Resources
- Perl - Discussion
Perl select Function
Description
This function sets the default filehandle for output to FILEHANDLE, setting the filehandle used by functions such as print and write if no filehandle is specified. If FILEHANDLE is not specified, then it returns the name of the current default filehandle.
select (RBITS, WBITS, EBITS, TIMEOUT ) calls the system function select( ) using the bits specified. The select function sets the controls for handling non-blocking I/O requests. Returns the number of filehandles awaiting I/O in scalar context, or the number of waiting filehandles and the time remaining in a list context
Syntax
Following is the simple syntax for this function −
select FILEHANDLE select select RBITS, WBITS, EBITS, TIMEOUT
Return Value
TRhis function returns the previous default filehandle if FILEHANDLE specified and Current default filehandle if FILEHANDLE is not specified.
Example
Following is the example code showing its basic usage −
#!/usr/bin/perl -w open(FILE,">/tmp/t.out"); $oldHandle = select(FILE); print("This is sent to /tmp/t.out.\n"); select($oldHandle); print("This is sent to STDOUT.\n");
When above code is executed, it produces the following result −
This is sent to STDOUT