Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select and filehandlers in perl 1

Status
Not open for further replies.

gammaman1

Programmer
Jun 30, 2005
23
US
Hi,

I'm trying to verify this line of code:

select( ( select( STDOUT ), $| = 1 )[ 0 ] );

this line is in a file that takes in 3 arguments.
From what I read from my oreilly book, does this mean that select will return the output filehandle if there is at least 1 arguement?

thanks,
gammaman1
 
There's nothing in that line of code to do with arguments to the file. What that code does (broken down):
Code:
# selects STDOUT as the default filehandle and returns STDOUT
select( STDOUT )

# also turns on autoflush on the currently selected filehandle (STDOUT)
# return a list - first element is STDOUT (filehandle), second is 1
select( STDOUT ), $| = 1

# return only the first element of the list (the filehandle STDOUT)
( select( STDOUT ), $| = 1 )[0]

# select the return value of above (STDOUT) as the currently selected filehandle
select( ( select( STDOUT ), $| = 1 )[0] );

As you can see from my discussion above, the outer select() statement is superflous, as STDOUT is already selected as the default output filehandle (NOTE: they're `filehandles', not `filehandlers').

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top