in reply to Unbuffered Output...
select returns the previously selected filehandle. So this bit:
( select( STDOUT ), $|=1 )
builds a two-element list where the first element contains the previously selected filehandle, and the second element is $|. Note that because the elements are evaluated in order, select( STDOUT ) has taken effect before $|=1 so that autoflush is set for STDOUT.
Now, we pick the first element from this list:
( select( STDOUT ), $|=1 )[ 0 ]
that is, the previously selected filehandle. This is passed to another select:
select( ( select( STDOUT ), $|=1 )[ 0 ] );
which means the filehandle that was selected before selecting STDOUT is re-selected. So what this ditty does is set autoflush on STDOUT without affecting which filehandle is currently selected while avoiding any temporary variables. It's a very neat, idiomatic bit of Perl.
Makeshifts last the longest.
|
|---|