digitize.pl 539 B

12345678910111213141516171819202122
  1. #!/usr/bin/env perl
  2. # Convert numbers to hex, when doing so is likely to increase compressibility.
  3. # This actually makes the script slightly longer, but generally makes it compress
  4. # to something shorter.
  5. #
  6. # Here we're targeting constants like 0xFF, 0xFFFF0000, 0x10101, 0x100000000, etc.
  7. sub digitize {
  8. my $number = shift;
  9. if ($number >= 256) {
  10. my $nn = `printf "%x" $number`;
  11. if ($nn =~ /^[01f]+$/i) { return "0x$nn"; }
  12. }
  13. return $number;
  14. }
  15. while (<>) {
  16. s/([^a-zA-Z0-9_])(\d+)/$1 . digitize $2/eg;
  17. print;
  18. }