in reply to About Broadcasting

You don't tell us how it does not run for you. From a cursory inspection, I guess that one of the errors is on the following line:

sysread(STDIN,$data,1024)||exit 0;

I suggest you change that line to:

if (! my $res = sysread(STDIN,$data,1024)) { if (defined $res) { print "End of user input. Thanks for playing.\n"; exit 0; } else { die "Couldn't read from input: $!"; }; };

But as it's inconvenient for me to duplicate your situation or to check what sysread returns when there is no input to be read from STDIN, maybe you care to tell us more about how your code does not work for you. Maybe Perl tells you something about it?

Replies are listed 'Best First'.
Re^2: About Broadcasting
by LH2007 (Initiate) on Nov 05, 2007 at 12:00 UTC
    I have changed this code but it warn: "Can't modify not in scalar assigment at   if (! my $res=sysread(STDIN,$data,1024)) zzz.... I'm very confuse,i don't know why and how

      Ah, that's a typo/thinko by me. Moving the expression part before the if statement works, but you could have tried out that yourself.

      ... my $res = sysread(STDIN,$data,1024); if (! $res) { if (defined $res) { print "End of user input. Thanks for playing.\n"; exit 0; } else { die "Couldn't read from input: $!"; }; }; ...

      Let me remind you that you still haven't told us at all how the program is failing for you and at what step. Without that knowledge, we cannot help you much and all we can do is guess based on cursory inspection of your code.

      A reply falls below the community's threshold of quality. You may see it by logging in.