Advertisement
bulrush

asciify: Return string with decimal value of every ctr, Perl

Aug 1st, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.77 KB | None | 0 0
  1. ###########################################################################
  2. # Display each ctr in decimal ascii like: "(65 66 32 38)"
  3. # In: long string
  4. # Out: string(s) showing decimal value of each ctr.
  5. sub asciify
  6. {my($l)=@_;
  7. my($s,$t,@a,@b,$i,$j,$procname,$le);
  8.  
  9. $procname="asciify";
  10.  
  11. $le=len($l);
  12. if ($le==0)
  13.     {
  14.     return "(zero len)";
  15.     }
  16. $s="(";
  17. for ($i=0; $i<=$le; $i++)
  18.     {
  19.     $t=substr($l,$i,1); # Get one ctr.
  20.     $s.=ord($t)." "; # Add decimal value of ctr.
  21.     } # for i
  22. $s=trim($s);
  23. $s.=")\n";
  24.  
  25. $s.="(";
  26. for ($i=0; $i<=$le; $i++)
  27.     {
  28.     $t=substr($l,$i,1); # Get one ctr.
  29.     if ($t=~m/[\t\l\r\x00\x01\x02]/) # Convert odd ctrs to space.
  30.         {
  31.         $t=" ";
  32.         }
  33.     $s.=" ".$t." "; # Add decimal value of ctr.
  34.     } # for i
  35. $s=trim($s);
  36. $s.=")";
  37.  
  38. return $s; # asciify
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement