in reply to print list to socket

The most popular pre-Perl way to simple record-based manipulations on unix was with sed and awk and Perl retains some sed regexp and quite a few awk features in memoriam, e.g.:
use English qw( -no_match_vars ); # use awk else at least alpha var names # and disable pre/post-match vars (not needed) # for performance # ... # note: $RS = "\n" is already the default! { local $ORS = "\r\n"; map { chomp; print $sock $_; } <FILE>; }
(updated thx to points made by johngg)
__________________________________________________________________________________

^M Free your mind!

Replies are listed 'Best First'.
Re^2: print list to socket
by johngg (Canon) on Jun 05, 2007 at 13:14 UTC
    Perhaps I'm missing something but I don't think that's going to work. Firstly, shouldn't the file read be outside the map? Seems to be a syntax error with it inside. Secondly, with the read in the right place all that gets passed to the print statement is the result of the chomp so you just pass a series of 1s to the socket. Thirdly, the lines passing through the map are not going to be interpreted as separate records so the lines will all get concatenated with a single "\r\n" at the end.

    Perhaps something along these lines would be better? (I've used "XX" instead of "\r" for visibility).

    use strict; use warnings; print map { chomp; qq{$_ XX\n} } <DATA>; __END__ line 1 line 2 line 3

    and the output

    line 1 XX line 2 XX line 3 XX

    If you do use English; it is a good idea to specify the -no_match_vars option to avoid a performance hit on all regexen in your script.

    # Avoid performance hit on regexen by specifying # -no_match_vars. # use English q{-no_match_vars};

    I hope this is of interest.

    Cheers,

    JohnGG