bin2hex: actually account for the number of bytes written
authorH. Peter Anvin <hpa@zytor.com>
Fri, 29 May 2009 22:47:20 +0000 (15:47 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Mon, 1 Jun 2009 04:53:18 +0000 (21:53 -0700)
Unlike C, in Perl printf() doesn't return the number of bytes written.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
utils/bin2hex.pl

index 0cb486e..778b699 100644 (file)
 ##
 ## -----------------------------------------------------------------------
 
-eval { use bytes; }; eval { binmode STDIN; };
+eval { use bytes; };
+eval { binmode STDIN; };
 
 $len = 0;
 while ( read(STDIN,$ch,1) ) {
     $cc = ord($ch);
-    $len += printf ("%x", $cc);
+    $s = sprintf("%x", $cc);
+    print $s;
+    $len += length($s);
     if ( $len > 72 ) {
        print "\n";
        $len = 0;