File: shuffle.pl

package info (click to toggle)
weechat-scripts 20161006-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,504 kB
  • ctags: 6,245
  • sloc: python: 37,508; perl: 27,405; ruby: 1,931; tcl: 226; lisp: 56; sh: 8; makefile: 7
file content (28 lines) | stat: -rw-r--r-- 867 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# This is a text shuffler
# This script is public domain
# Author: Sid Vicious (Trashlord) <dornenreich666@gmail.com>

use warnings;
use strict;

weechat::register("shuffle", "Trashlord", "0.1", "Public domain", "Simple text shuffler", "", "");
weechat::hook_command("shuffle", "<msg>", "<msg> - message to shuffle", "", "", "cmd_shuffle", "");

#Text shuffler
sub cmd_shuffle {
	my ($data, $buffer, $text) = (shift, shift, shift);
	my $final;
	for(split(" ", $text)) { #We're splitted here, so we can keep the spaces in order, and words in order. we just shuffle letters
		my $len = length $_;
		my $out;
		while ($len > 0) {
			my $rand = int(rand($len)); 
			my $letter = substr($_, $rand, 1); 
			$len--;
			substr($_, $rand, 1, "");
	        	$out .= $letter;
		}
        	$final .= $out." ";
	}
	weechat::command($buffer, $final);
}