#!/usr/bin/perl package fortunebot; use strict; use Fortune; if ($ARGV[0]) { print getfortune($ARGV[0]); } sub getfortune { my $fortfile = shift; return unless ($fortfile =~ /^\w+$/); return unless (-f '/usr/share/games/fortune/' . $fortfile); my $ffile = new Fortune ('/usr/share/games/fortune/' . $fortfile); $ffile->read_header(); my $quotelen=10000; my $quote; # only return quotes < 500 chars while ($quotelen > 500) { $quote = $ffile->get_random_fortune (); $quotelen=length($quote); } return $quote; } 1;