Skip to content

Instantly share code, notes, and snippets.

@smanurung
Created February 27, 2016 15:40
Show Gist options
  • Save smanurung/c331df5757e1f13dccc2 to your computer and use it in GitHub Desktop.
Save smanurung/c331df5757e1f13dccc2 to your computer and use it in GitHub Desktop.
random topic generator for blogging
#!/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