summaryrefslogtreecommitdiff
path: root/shared.pl
blob: 16993ab5d5723f6e72dcbf7d0a982013ab80efa3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File to hold shared subroutines


# Handle digging into non-scalar tags and other deep arrays
# 	@_[0] -> array tag/deep array
sub array_handler {
	my @output;

	for my $i (@_){
		# If another array, recursively handle
		if (ref($i) eq 'ARRAY'){
			push(@output, array_handler(@$i));
		}

		# If scalar, append to output normally
		elsif (!ref($i)){
			push(@output, "$i");
		}
	}

	return @output;
}


# Wrapper to handle sqlite commands, return an array of returned lines from sqlite output
# 	@_[0]            -> database handle
# 	@_[1]            -> command/statement
# 	@_[2] (optional) -> output statement
sub db_cmd {
	my $sth = $_[0]->prepare($_[1]);

	if ($sth->execute < 0){
		die $DBI::errstr;
	}

	# DEBUG
	if (!$options{quiet} and defined $_[2]){
		print "$_[2]\n";
	}

	# Build output array
	return($sth->fetchall_arrayref);
}

1;