home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl -w
-
- =pod
-
- Simple fortune program
-
- =cut
-
- use strict;
-
- my $fortune = fortune();
- print $fortune;
-
- exit;
-
- sub fortune {
- my ($fortune_dir) = "C:\\pcplus\\perl\\issue164\\fortunes";
- opendir FORT , $fortune_dir or die "$fortune_dir doesn't exist!\n";
- my (@fort_files) = grep(!/\./, (readdir FORT));
-
- closedir FORT;
- my ($target) = pickoneof(@fort_files);
- open (FORT, "<$fortune_dir/$target") or die "unable to read $target\n";
- $/ = '%';
- my (@forts) = (<FORT>);
- close FORT;
- chomp(@forts);
- return pickoneof(@forts);
- }
-
- sub pickoneof (@) {
- # given an argument list, return a random scalar element
- return $_[int(rand(scalar(@_) -1))];
- }
-
-