Created
February 27, 2016 15:40
-
-
Save smanurung/c331df5757e1f13dccc2 to your computer and use it in GitHub Desktop.
random topic generator for blogging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
my $topicdb = 'topic.txt'; | |
open(my $db, '<', $topicdb) or die $!; | |
my $count = 0; | |
my %topic; | |
while(<$db>){ | |
if($_ =~ "^--"){ | |
$count++; | |
} else { | |
$topic{$count} = $topic{$count} . $_; | |
} | |
} | |
close($db); | |
$luckyone = int(rand($count)); | |
print STDOUT $topic{$luckyone+1}; | |
exit 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment