What does “select((select(s),$|=1)[0])” do in Perl?

后端 未结 7 686
执念已碎
执念已碎 2020-12-03 01:19

I\'ve seen some horrific code written in Perl, but I can\'t make head nor tail of this one:

select((select(s),$|=1)[0])

It\'s in some netwo

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 01:45

    In another venue, I once proposed that a more comprehensible version would be thus:

    for ( select $fh ) { $| = 1; select $_ }
    

    This preserves the compact idiom’s sole advantage that no variable needs be declared in the surrounding scope.

    Or if you’re not comfortable with $_, you can write it like this:

    for my $prevfh ( select $fh ) { $| = 1; select $prevfh }
    

    The scope of $prevfh is limited to the for block. (But if you write Perl you really have no excuse to be skittish about $_.)

提交回复
热议问题