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

Hey Monks,

I'm stuck on a really confusing error which i really can't figure out. I am trying to read from a socket and display a variable, however i need to chomp the variable to do a comparison.

The code i have is:
my $buf = <$client>; chomp $buf; print $buf;
Which produces no output, however when i remove the chomp line it prints what i would expect from $buf, with a newline.

$client is a socket which i have set up ie
while (my @ready = $sel->can_read) { foreach $client (@ready) {


If i have left anything out of my explanation which is needed please ask.

Thanks a lot for any help

Neil Archibald
- /dev/IT -

Replies are listed 'Best First'.
Re: Confusing Socket Error
by pg (Canon) on Oct 23, 2003 at 16:46 UTC

    Your stuff is just okay, it didn't get flushed to screen right the way as there is no return at the end.

    Just do

    $|++;
    at the beginning of your code.

      Hi,
      I tried what you said, but it seems to have no effect :)
      Thanks anyway though

      Neil Archibald
      - /dev/IT -
        Do some more printing, to see where everything goes, at least while you're investigating:

        my $buf = <$client>; my $whatitwas = $buf; print 'Chomping ', chomp $buf, " chars\n"; print "It used to be $whatitwas, but now it is $buf\n";

        Have you modified $/ at all?