Guest User

Untitled

a guest
Jun 22nd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use latest;
  4.  
  5. my $max = 140;
  6. my $abl = 4;
  7. my @cs = ( 'A' .. 'Z', 'a' .. 'z', '0' .. '9', split //, '.%$&*' );
  8.  
  9. sub tok() {
  10. join '', map { @cs[ rand @cs ] } 1 .. $abl;
  11. }
  12.  
  13. my @words = split /\s+/, do { local $/; <> };
  14. my @length = map { $_->[1] } sort { $b->[0] <=> $a->[0] }
  15. grep { $_->[0] > $abl }
  16. map { [ length $words[$_] => $_ ] } 0 .. $#words;
  17. my @abbr = ();
  18. while ( length( join ' ', @words ) > $max ) {
  19.  
  20. if ( @length ) {
  21. my $pos = shift @length;
  22. my $abbr = tok;
  23. push @abbr, [ $abbr, $words[$pos] ];
  24. $words[$pos] = $abbr;
  25. }
  26. else {
  27. # brute force
  28. my $span = 1 + int rand 4;
  29. my $pos = int rand @words - $span;
  30. my $abbr = tok;
  31. push @abbr, [ $abbr, join ' ', splice @words, $pos, $span, $abbr ];
  32. }
  33. }
  34.  
  35. tweet( join ' ', @words );
  36. @abbr = map "s/$_->[0]/$_->[1]/", @abbr;
  37. CHUNK: while ( @abbr ) {
  38. my @abc = ();
  39. while ( @abbr ) {
  40. push @abc, shift @abbr;
  41. if ( length join( "\n", @abc ) > $max ) {
  42. unshift @abbr, pop @abc;
  43. tweet( join "\n", @abc );
  44. next CHUNK;
  45. }
  46. }
  47. tweet( join "\n", @abc );
  48. }
  49.  
  50. sub tweet {
  51. my $msg = shift;
  52. system 'tweet', $msg;
  53. }
  54.  
  55. # vim:ts=2:sw=2:sts=2:et:ft=perl
Add Comment
Please, Sign In to add comment