Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

need help urgent using @ARGV

by mohan@1 (Initiate)
on Jan 19, 2012 at 02:29 UTC ( #948658=perlquestion: print w/ replies, xml ) Need Help??
mohan@1 has asked for the wisdom of the Perl Monks concerning the following question:

I am new to perl but after spending late nights for some days , i was able to generate code for database backup. the code will ask you enter servername , enter database name if i enter it will take backup suppose my code is in backup.pl now the thing is i need to get database backup by entering like this perl backup.pl -i servername -d databasename if i hit enter it should take backup of given server name and database name.

My code:

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"; }

Comment on need help urgent using @ARGV
Download Code
Re: need help urgent using @ARGV
by InfiniteSilence (Curate) on Jan 19, 2012 at 03:54 UTC
    use strict; use Getopt::Long; my $database = ''; my $servername = ''; my $result = GetOptions ("database=s" => \$database, # string + "servername=s" => \$servername); # stri +ng print qq|USAGE: perl backup.pl --database=<database> --servername=<ser +vername>\\ n| unless ($database && $servername); my $stmnt =qq|BACKUP database "$database" TO DISK = N'c:\\bak\\master. +dmp'\n|; print $stmnt;

    You get the idea.

    Celebrate Intellectual Diversity

Re: need help urgent using @ARGV
by ww (Bishop) on Jan 19, 2012 at 03:57 UTC
    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.

Re: need help urgent using @ARGV
by choroba (Abbot) on Jan 19, 2012 at 09:34 UTC
    You might consider changing the title of your post to something more informative (like "Database backup"). It would for example help others when searching for DB related problems.
Re: need help urgent using @ARGV
by talexb (Canon) on Jan 19, 2012 at 15:06 UTC

    I'm not sure why you need to write a Perl script to do this -- wouldn't bash (or friends and relations) be a simpler platform for this task?

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://948658]
Approved by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2014-09-21 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls