http://www.perlmonks.org?node_id=352477


in reply to Battling Getopt::Long

A Few changed and your code will work..

Try changing

my %opts=(GetOptions( 'help|?' => \$help, 'server' => \$server, 'user' => \$user, 'password' => \$password ));
to
GetOptions (\%opts, qw( help|h|? server=s user=s password=s ));
also put everything after
&Help; }
into and elsif statement something like
&Help; } elsif( defined $opts{server} && defined $opts{user} && defined $opts{p +assword} ) { my $mytime=(time); ... } else { &Help; }
Then for your database connection bit try using the following:
my $dbh; my $DSN = "driver={SQL Server};Server=$opts{server};database=$database +;"; if ($dbh = DBI->connect("dbi:ODBC:$DSN","$opts{user}","$opts{password} +")) { &Logger ("...Success: connected to database $opts{server}\\$databa +se\n"); } else { &Logger("ERROR - Cannot connect to DB: $dbh->errstr()\n"); }
also you can't have $sth->finish if you havent prepared or ecexuted a $sth statement I.e.
my $query = "select * from sometable"; my $sth = $dbh->prepare($query); for my $rec (@records) { $sth->execute(@$rec); } $setsth->finish();
Type Stuff - HTH

Update:Sorry Typo... change $setsth->execute(@$rec); to $sth->execute(@$rec);

-----
Of all the things I've lost in my life, its my mind I miss the most.

Replies are listed 'Best First'.
Re: Re: Battling Getopt::Long
by Smaug (Pilgrim) on May 12, 2004 at 08:48 UTC
    Thanks AcidHawk.
    A quick question...
    From the code you so kindly provided, why is it $setsth->finish();
    and not $sth->finish();
    Thanks again.

    Dazed and confused,
    Smaug.