Hello,

I'll try to explain what I think is happening, hoping it may be helpful.

my @replies ; 
# here we're creating an IO::Select object, good
my $sel = IO::Select->new();
# and adding the socket handle, good also
$sel->add($socket);

# we wait until there are available data to be read.  
# This call will block until we have data on one of the added sockets.
while (@ready = $sel->can_read())
{
     foreach (@ready)  # we iterate through all sockets with data
     {
        push @replies, <$_> ; # we read from this handle until we reach EOF
        # adding every line to @replies.  If the server sends us one line only,
we'll wait
        # until it finishes sending everything it has.
    }
    # here, we're done reading everything from every socket.  why are we
iterating again?
}

The problem I believe is caused by the push statement.  push takes an array and
a LIST and appends the list to the array.  So, it evaluates the <$_> in list
context.  

Here is what *might* work:

#!/usr/bin/perl -w
use IO::Socket;
use IO::Select;

my $socket = IO::Socket::INET->new( PeerAddr => 'www.yahoo.com:80') or die
"Connect Error\n";

print $socket "GET /\n\n";
my @replies ; 
my $sel = IO::Select->new();
$sel->add($socket);

while (@ready = $sel->can_read()){
        foreach (@ready){
                my $l = <$_>;
                close $_ and next unless defined $l;
                push @replies, $l ;
        }
}

print "@replies\n";



On Sat, 2 Jun 2001 18:05:47 -0700 (PDT), David Milne said:
> Hi, 
>  I am having problems with the IO::Select classes.
>  I am trying to read a long string from a pop server.
>  Accordingly, I have something along the lines of 
>  
>  .....
>  my @replies ; 
>  my $sel = IO::Select->new();
>  $sel->add($socket);
>  
>  while (@ready = $sel->can_read())
>  {
>       foreach (@ready)
>      {
>      push @replies, <$_> ;
>      }
>  }
>  
>  Problems:
>  print statements (not shown here) tell me that
>  
>  1)  Socket appears to block, although @ready should
>  only contain a list of readable filehandles.
>  
>  2) If Server closes the connection, the while
>  condition evaluates to true always and it loops
>  forever.



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

Reply via email to