Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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 ));
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
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,

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2015-11-30 11:13 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (769 votes), past polls