Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use warnings;
- use strict;
- use Getopt::Long;
- my $bg = '';
- my $graph = '';
- my $filename = "graph.png";
- my $db_dump = '';
- # displays my help if there are no arguments or one of the specified options
- usage() if (@ARGV < 1 or ! GetOptions('b=i' => \$bg, 'g' => \$graph, 'f=s' => \$filename, 'd' => \$db_dump));
- print "#---------------------#\n";
- print "DEBUG info\n";
- print "bg: $bg g: $graph filename: $filename and d: $db_dump\n";
- print "#---------------------#\n\n";
- if ($db_dump == 1) { &dbconnect(); print $1; }
- sub usage {
- use Term::ANSIColor qw(:constants);
- print "Unknown option: @_\n" if ( @_ );
- print "usage: $0 [", BOLD, "-b #", RESET, "] [", BOLD, "-g", RESET, "] [", BOLD,"-f file", RESET, "] [ ", BOLD "-d", RESET, " ]\n\n";
- print "\t", BOLD, "-b", RESET, " : Specify a blood sugar value\n";
- print "\t", BOLD, "-g", RESET, " : Utilize graphing feature\n";
- print "\t", BOLD, "-f", RESET, " : Specify output PNG filename. Must be used with ", BOLD, "-g", RESET, ". Default name is graph.png\n";
- print "\t", BOLD, "-d", RESET, " : Display all fields from the BG database\n\n";
- exit;
- }
- sub dbconnect {
- use DBI;
- print "hey! you're about to connect!!\n";
- my $dbh = DBI->connect(
- "dbi:SQLite:dbname=cosc279_bgs.db",
- "",
- "",
- { RaiseError => 1 },
- ) or die $DBI::errstr;
- return $1;
- }
- sub db_dump {
- my $data = $1->selectall_arrayref("SELECT * FROM bgtable BY Date DESC");
- foreach (@$data) {
- my ($id, $date, $time, $bg) = @$_;
- print "$id\t$date\t$time\t$bg\n";
- }
- exit;
- }
- sub grapher {
- print "Utilize the grapher\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement