Please clarify the narrative portion of your SOPW -- which may be achieved, in some part, by using conventional grammar, syntax and punctuation (AKA "complete sentences with capitalization and punctuation").
Aside: it appears that what you tell us up to the words "suppose my code is in backup.pl is irrelevant to the question you didn't ask but that, on a WAG, may be, "how do I revise this code to use..." perl backup.pl -i servername -d databasename
Of course, the code you show offers very little support for (or "relevance to") my WAG, so maybe you'd better clarify your thinking... and then your question.
And, for the benefit of others with better brains, less time or patience, here's what your (posted) code is apparently supposed to look like:
use strict;
use Win32::SqlServer qw(SCALAR);
print "Please enter DB name:\n";
my $name = <STDIN>;
chomp($name);
# Log in to server .
my $sqlsrv = Win32::SqlServer::sql_init('localhost', 'geff', 'gentle',
+ 'Northwind');
# Our SQL statement.
my $stmnt = <<SQLEND;
BACKUP database "$name" TO DISK = N'c:\\bak\\master.dmp'
SQLEND
# Run query.
my $result = $sqlsrv->sql($stmnt, SCALAR);
# Print results.
foreach my $name (@$result) {
print "$name\n";
}
Update, clarifying: That is, that's what the code would have looked like if you'd bothered reading the advice about formatting in Writeup Formatting Tips. That is NOT to say it's anything even close to good code. |