in reply to I want to know exactly what comes through a socket
They're unprintable, so you can't see them by definition. You could replace them with some form of representation. For example,
Untested.sub unchomp { $_ = $_.$/ foreach @_ ? @_ : $_; } while (<$sock>) { chomp; # Don't want to transform the newline. s/([^[:print:]])/sprintf("\\x{%02X}", ord($1))/eg; unchomp; print; }
Update: Tested. Fixed bugs.
Update: Here's an alternative representation (for charsets based on ASCII):
sub unchomp { $_ = $_.$/ foreach @_ ? @_ : $_; } while (<$sock>) { chomp; # Don't want to transform the newline. s/([\x01-\x1F])/'^' . chr(ord('@')+ord($1))/ s/([^[:print:]])/sprintf("\\x{%02X}", ord($1))/eg; unchomp; print; }
The first program outputs
test\x{1}\x{2}\x{1D}test
and the second outputs
test^A^B^]test
for the result of the Perl expression
"test".chr(1).chr(2).chr(29)."test"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: I want to know exactly what comes through a socket
by GrandFather (Saint) on Nov 23, 2005 at 21:51 UTC | |
|
Re^2: I want to know exactly what comes through a socket
by ivanatora (Sexton) on Nov 23, 2005 at 21:45 UTC | |
by ikegami (Patriarch) on Nov 23, 2005 at 21:57 UTC |