I had a similiar problem with Cisco Discovery Protocol. When the neighbors (switches/routers) showed up they included a "NULL" 00 HEX in the description which threw a new line into the output screwing up my logs. Here's How I fixed it. Create a "sub clean" which converts the string to hex, flushes out the hidden strings, converts back to ascii then returns the sanitized string. This has since solved all my output values...
$item = caschex(1, $item); #A->H if($debug == 1) { print "HEX: \"$item\"\n"; } $item = caschex(2, $item); #H->A if($debug == 1) { print "ASCII: \"$item\"\n"; } $item =~ s/^\s+//; #remove Leading whitespace $item =~ s/\s+$//; #remove trailing whitespace $item =~ s/\s+/ /g; #replace multiple spaces with one chomp($item); #remove newline character ######################################################## # Sub caschex # # USAGE: Removes hidden strings in variables.. Addition to Clean # # v1.0.0 -> 2006-04-20 # Born # ###### # my ($item) = cipdec(1, $ip); #1 = A->H, 2 = H->A + ###### # sub caschex { # 1 = ASCII TO HEX # 2 = HEX TO ASCII ########## my $debug = 0; ########## if($debug == 1) { print "---------------------------------- ENTERED +SUB: \"caschex\"\n"; } my $opt = undef; my $item = undef; my $ret = undef; my $val = undef; $opt = shift(@_); $item = shift(@_); if($debug == 1) { print "\n\n"; print "OPT: \"$opt\"\n"; print "ITEM: \"$item\"\n"; } ############################# OPT 1 if($opt == 1) { if($debug == 1) { print "CONVERT ASCII TO HEX\n"; } $key = undef; $val = undef; foreach $key (split//,$item) { if($debug == 1) { print "KEY: \"$key\"\n"; } ($key) = sprintf("%02lx", ord $key); if($debug == 1) { print "HEX KEY: \"$key\"\n"; } if(($key eq "00") || ($key eq "1b")) { if($debug == 1) { print "FOUND NULL IN ASCII VARIABLE... REPLA +CE WITH SPACE\n"; } $key = " "; #NOTE: A SPACE IN HEX IS "20" ($key) = sprintf("%02lx", ord $key); if($debug == 1) { print "HEX KEY: \"$key\"\n"; } } $val .= $key; if($debug == 1) { print "VAL: \"$val\"\n"; } } if($debug == 1) { print "COMPLETE VAL: \"$val\"\n"; } } ############################# EO OPT 1 ############################# OPT 2 if($opt == 2) { if($debug == 1) { print "CONVERT HEX TO ASCII\n"; } $key = undef; $val = undef; foreach $key ($item =~ /[a-fA-F0-9]{2}/g) { if($debug == 1) { print "HEX KEY: \"$key\"\n"; } if(($key eq "00") || ($key eq "1b")) { if($debug == 1) { print "FOUND NULL IN HEX.. REPLACE WITH SPAC +E\n"; } $key = 20; if($debug == 1) { print "HEX KEY: \"$key\"\n"; } } ($key) = chr(hex $key); if($debug == 1) { print "ASC KEY: \"$key\"\n"; } $val .= $key; if($debug == 1) { print "VAL: \"$val\"\n"; } } if($debug == 1) { print "COMPLETE VAL: \"$val\"\n"; } } ############################# EO OPT 2 $ret = $val; if($debug == 1) { print "RET: \"$ret\"\n"; } if($debug == 1) { print "---------------------------------- LEAVING +SUB: \"caschex\"\n"; } $debug = 0; return($ret); } # # ############################################## EO SUB CASCHEX

In reply to Re: Very weird things when printing (may be an encoding issue?) by t_rex_joe
in thread Very weird things when printing (may be an encoding issue?) by dottornomade

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.