If I try it without the single quotes within the func declaration, I get a strict subs error
Something like this?
#!/bin/env perl
# create a SQLite test database
use strict;
use warnings;
use DBI;
my $db = shift @ARGV || 'no_name.splite';
my $dbh = DBI->connect(
"dbi:SQLite:$db", "", "",
{
RaiseError => 1,
sqlite_see_if_its_a_number => 1,
PrintError => 0
}
);
$dbh->func('sqrt_s_s', -1, \&sqrt_sum_of_sqrs, 'create_function'); # n
+eed length function
my @rowa = $dbh->selectrow_array( "select 3 as A, 4 as B, sqrt_s_s( 3,
+ 4 ) as C" );
print join( "\t", @rowa ), "\n";
sub sqrt_sum_of_sqrs {
my $sum_sqrs = 0.0;
map { $sum_sqrs += $_ ** 2 } @_;
return sqrt( $sum_sqrs );
}
Update: So now you need to research three things.
- How would you prompt a user for input?
- How to get the user input?
- How do you pass the user input into your function?