bwt_string_symbolic.pl 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/perl
  2. # Bzip2-like (symbolic) compressor/decompressor, for compressing a given string.
  3. use utf8;
  4. use 5.036;
  5. use lib qw(../lib);
  6. use Compression::Util qw(:all);
  7. local $Compression::Util::VERBOSE = 0;
  8. foreach my $file (__FILE__) {
  9. say "Compressing: $file";
  10. my $str = do {
  11. local $/;
  12. open my $fh, '<:utf8', $file;
  13. <$fh>;
  14. };
  15. my $enc = bwt_compress_symbolic([map { ord($_) } $str =~ /(\X)/g]);
  16. my $dec = bwt_decompress_symbolic($enc);
  17. say "Original size : ", length($str);
  18. say "Compressed size: ", length($enc);
  19. if ($str ne join('', map { chr($_) } @$dec)) {
  20. die "Decompression error";
  21. }
  22. say '';
  23. }
  24. __END__
  25. # International class; name and street
  26. class 国際( なまえ, Straße ) {
  27. # Say who am I!
  28. method 言え {
  29. say "I am #{self.なまえ} from #{self.Straße}";
  30. }
  31. }
  32. # all the people of the world!
  33. var 民族 = [
  34. 国際( "高田 Friederich", "台湾" ),
  35. 国際( "Smith Σωκράτης", "Cantù" ),
  36. 国際( "Stanisław Lec", "południow" ),
  37. ];
  38. 民族.each { |garçon|
  39. garçon.言え;
  40. }