Gorby has asked for the wisdom of the Perl Monks concerning the following question:

Hello wise monks. I have a program that uses sockets. In this program appears the following line:
$input=<$socket>;
Will this cause my program to wait indefinitely for something to come through from the socket before executing any further code below it? I need help in understanding how this line behaves. Thanks!

Replies are listed 'Best First'.
Re: Waiting forever?
by broquaint (Abbot) on Mar 03, 2003 at 12:37 UTC
    Will this cause my program to wait indefinitely for something to come through from the socket before executing any further code below it?
    If the socket is blocking then it could potentially wait forever, however if it's non-blocking then there'll be no waiting. To switch the behaviour of a socket you should be able to use the blocking() method inherited from IO::Handle e.g
    $socket->blocking( 1 );
    Will turn on non-blocking for $socket. See perlipc and IO::Handle for more info.
    HTH

    _________
    broquaint

Re: Waiting forever?
by robartes (Priest) on Mar 03, 2003 at 12:41 UTC
    In default conditions, this will wait until it has collected one line of input (i.e. everything up to $/, the input record separator) before returning control to the program. To avoid this behaviour, have a look at select (the four argument version) to poll file descriptors to see whether or not they have input waiting to be read, and have a look at perlfaq8 which has an item on nonblocking IO. This last is also a good search string to find information on avoiding blocking on reads.

    Good luck!

    CU
    Robartes-