Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Battling Getopt::Long

by AcidHawk (Vicar)
on May 11, 2004 at 15:25 UTC ( #352477=note: print w/ replies, xml ) Need Help??


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.


Comment on Re: Battling Getopt::Long
Select or Download Code
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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2014-08-28 09:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (259 votes), past polls