Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

need advice urgent

need advice urgent

need advice urgent

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>;
# 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'

# Run query.
my $result = $sqlsrv->sql($stmnt, SCALAR);

# Print results.
foreach my $name (@$result) {
print "$name\n";

RE: need advice urgent

take a look at Getopt::Std module.

RE: need advice urgent

can you please put it in my code

im getting errors .please help

RE: need advice urgent

You can run a command like this


perl myscript.pl username servername

simply by adding lines like these into your code:



Further parameters are just $ARGV[2], $ARGV[3] etc.

If I want something fancier I use


use Getopt::Long;
#get parameters
GetOptions("version=s" =>\$param{version},"fast=s" =>\$param{fast});
if(! $param{version})
    print "\nYou must specify the version attribute of the project e.g. -version 6.4.2_215\n";
    exit 1;
if(! $param{fast})
    print "\nYou must specify whether or not fast mode is to be used i.e. -fast yes|no\n";
    exit 1;
my $output_name=$param{version};
my $fast=$param{fast};
print "$output_name\n$fast\n"

This enables you to use a command like:


perl myscript.pl -fast yes -version 6.5.2_675

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close