in reply to Re^2: String manipulation
in thread String manipulation

Looks like the "keep alive" is a null character (ASCII value 0).

while (<$sock>) { s/^\0+//; # Remove leading null characters print; # print to screen as well to show raw data and connectio +n chomp($_);

should fix the problem.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^4: String manipulation
by bajangerry (Sexton) on Aug 07, 2007 at 21:49 UTC
    Thanks, moritz indicated that this was a "not so safe" way of doing this, any suggestions of a safer means?
      To be clear: moritz was talking about "removing all initial non-whitespace characters", and saying that it would be "not so safe" to do that -- and he would be right, in the sense that sometimes, initial non-whitespace characters might not be garbage, and it would be bad to remove them.

      GrandFather has proposed a different approach: just remove null bytes. There is nothing "unsafe" about this -- null bytes carry no relevant information, and they just get in the way. Deleting null bytes from your strings is a Good Thing.

      What moritz suggested was stripping any non-whitespace characters. The regex I suggested just removes leading ASCII null characters. For the task at hand that should be completely safe.

      I strongly recommend that you learn about Perl regular expressions. See perlretut, perlre and perlreref. A browse around the Tutorials section here is likely to pay off too.


      DWIM is Perl's answer to Gödel