Perl select Function
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
Following is the simple syntax for this function −
select FILEHANDLE select select RBITS, WBITS, EBITS, TIMEOUT
TRhis function returns the previous default filehandle if FILEHANDLE specified and Current default filehandle if FILEHANDLE is not specified.
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