the "system" and "print" function thingy

Discussion in 'Perl Misc' started by flying lumberjack, Mar 4, 2004.

  1. I am currently trying to learn PERL and have a very limited programing
    background (QBASIC). So to do this i decided to have a bit of a mess
    around with an example of a very basic telnet script from "Erik
    Olson's Programming with Perl Modules". With the print function it
    allows you to display the text you want to display on the clients
    screen. Can you display the results from the "system" function on both
    the server and the client, as i can only get it to display the results
    on the server screen.

    Here is the script (i did't write this):
    use IO::Select;

    # Create a socket to listen on.
    #
    my $listener =
    IO::Socket::INET->new( LocalPort => 8008, Listen => 5, Reuse =>
    1 );

    die "Can't create socket for listening: $!" unless $listener;
    print "Listening for connections on port 8008\n";

    my $readable = IO::Select->new; # Create a new IO::Select
    object
    $readable->add($listener); # Add the listener to it

    while(1) {

    # Get a list of sockets that are ready to talk to us.
    #
    my ($ready) = IO::Select->select($readable, undef, undef,
    undef);
    foreach my $s (@$ready) {

    # Is it a new connection?
    #
    if($s == $listener) {

    # Accept the connection and add it to our readable
    list.
    #
    my $new_sock = $listener->accept;
    $readable->add($new_sock) if $new_sock;

    print $new_sock "Welcome!\r\n";

    } else { # It's an established connection

    my $buf = <$s>; # Try to read a line

    # Was there anyone on the other end?
    #
    if( defined $buf ) {

    # If they said goodbye, close the socket. If not,
    # echo what they said to us.
    #
    if ($buf =~ /goodbye/i) {
    print $s "See you later!\n";
    $readable->remove($s);
    $s->close;


    } else {
    system ("$buf\n");
    }

    } else { # The client disconnected.

    $readable->remove($s);
    $s->close;
    print STDERR "Client Connection closed\n";

    }
    }
    }
    }
     
    flying lumberjack, Mar 4, 2004
    #1
    1. Advertising

  2. flying lumberjack

    gnari Guest

    "flying lumberjack" <> wrote in message
    news:...

    [snipped long FAQ]

    perldoc -f system
    perldoc -q "Why can't I get the output of a command with system()?"

    gnari
     
    gnari, Mar 4, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. M.E.
    Replies:
    0
    Views:
    364
  2. David Graham

    bucies image selector thingy

    David Graham, Jul 3, 2003, in forum: HTML
    Replies:
    4
    Views:
    567
    brucie
    Jul 3, 2003
  3. keto
    Replies:
    0
    Views:
    1,022
  4. Evertjan.
    Replies:
    2
    Views:
    195
    Techy
    Nov 23, 2003
  5. techy techno
    Replies:
    1
    Views:
    118
    Evertjan.
    Nov 23, 2003
Loading...

Share This Page