in reply to script to listen on a port & redirect to a file

You forgot the print.

Also, opening and closing the file for each line received is wasteful. Open the file before the loop.

Replies are listed 'Best First'.
Re^2: script to listen on a port & redirect to a file
by a31modela (Initiate) on Aug 14, 2015 at 18:58 UTC

    thanks for the quick reply.... so are you saying the script should look like this ?

    my $new_sock = $sock->accept(); open my $fh, '>>', $file or die $!; while(<$new_sock>) { print <$fh>; #######close $fh; }

    Is this what you mean?

    thanks, steve

      I think he means:

      [...] open my $fh, '>>', $file or die $!; while(<$new_sock>) { print $fh $_; } [...]

      Alternatively, just add:

      $|++

      before the "$sock->accept()" call in your original script and the redirect to file will work.