#!/usr/bin/perl
#
# random bible v0.0.5 - Outputs random bible verses
# Copyright (C) 2004, 2005 Stian Skjæveland
#
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#

use strict;
use Term::ANSIColor;

my ($int_lines,
    $head,
    $vers,
    $download,
    $wget_path,
    @lines);
my $biblefile="$ENV{'HOME'}/.biblerc";
my $randint=int(rand(20));

open(BIBLE, "$biblefile") || &biblefile_not_found();
@lines=<BIBLE>;
close(BIBLE);
($head, $vers)=split('/', $lines[$randint-1]);
print colored ['black on_white'], "$head";
print color 'reset';
print "\n$vers";

sub biblefile_not_found() {
  print "$0: can't open $biblefile: $!\nDo you want me to download $biblefile for you? ([y]es, [n]o) [y] ";
  chomp($download=<STDIN>);
  if ($download=~/[Nn]/) {
    die("$0: has quit without downloading $biblefile .\n");
  } else {
    $wget_path="/usr/bin/wget";
    if (! -e $wget_path) {
      die("$0: can't download $biblefile because you don't have wget in $wget_path .\n");
    }
    print "$0: now downloading $biblefile from the internet using wget ...\n";
    `wget --output-document=$ENV{'HOME'}.biblerc http://stian.atlantiscrew.net/src/.biblerc`;
    print "\n$0: all done.\n";
  }
}

=head1 NAME

random bible - Outputs random bible verses.

=head1 DESCRIPTION

This program outputs random verses from The Holy Bible - King James Version (English).

=head1 USAGE

You have to create a file called ~/.biblerc with this syntax:

John 3.16/For God so loved the world, that he...

Remember that the maximum amount of bible verses are 20.
I have a sample for located at:

http://stian.atlantiscrew.net/src/.biblerc

=head1 ENVIRONMENT

random bible requires the $HOME environment variable.

=head1 BUGS

Please forward any bugs to; stian at atlantiscrew period net.

=head1 AUTHOR

Stian Skjæveland

=head1 COPYRIGHT

Copyright (C) 2004, 2005 Stian Skjæveland

This program is free software; you can redistribute it
and/or modify it under the same terms as Perl itself.

=cut
