Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use latest;
- my $max = 140;
- my $abl = 4;
- my @cs = ( 'A' .. 'Z', 'a' .. 'z', '0' .. '9', split //, '.%$&*' );
- sub tok() {
- join '', map { @cs[ rand @cs ] } 1 .. $abl;
- }
- my @words = split /\s+/, do { local $/; <> };
- my @length = map { $_->[1] } sort { $b->[0] <=> $a->[0] }
- grep { $_->[0] > $abl }
- map { [ length $words[$_] => $_ ] } 0 .. $#words;
- my @abbr = ();
- while ( length( join ' ', @words ) > $max ) {
- if ( @length ) {
- my $pos = shift @length;
- my $abbr = tok;
- push @abbr, [ $abbr, $words[$pos] ];
- $words[$pos] = $abbr;
- }
- else {
- # brute force
- my $span = 1 + int rand 4;
- my $pos = int rand @words - $span;
- my $abbr = tok;
- push @abbr, [ $abbr, join ' ', splice @words, $pos, $span, $abbr ];
- }
- }
- tweet( join ' ', @words );
- @abbr = map "s/$_->[0]/$_->[1]/", @abbr;
- CHUNK: while ( @abbr ) {
- my @abc = ();
- while ( @abbr ) {
- push @abc, shift @abbr;
- if ( length join( "\n", @abc ) > $max ) {
- unshift @abbr, pop @abc;
- tweet( join "\n", @abc );
- next CHUNK;
- }
- }
- tweet( join "\n", @abc );
- }
- sub tweet {
- my $msg = shift;
- system 'tweet', $msg;
- }
- # vim:ts=2:sw=2:sts=2:et:ft=perl
Add Comment
Please, Sign In to add comment