Re: foreach and next

2012-04-09 Thread Rob Dixon
On 09/04/2012 14:24, Vyacheslav wrote: My code my %attr = ( PrintError => 0, RaiseError => 0 ); my $dbh = DBI->connect($dsn, $user, $pass, \%attr); unless ($dbh) { next; } my $query = "SHOW DATABASES"; I use unless ($dbh) { next; } and this work fine. Thanks 09.04.2012 01:22, Jim Gibson напи

Re: foreach and next

2012-04-09 Thread Vyacheslav
My code my %attr = ( PrintError => 0, RaiseError => 0 ); my $dbh = DBI->connect($dsn, $user, $pass, \%attr); unless ($dbh) { next; } my $query = "SHOW DATABASES"; I use unless ($dbh) { next; } and this work fine. Thanks 09.04.2012 01:22, Jim Gibson написал: At 12:50 AM + 4/9/12, Vyachesl

Re: foreach and next

2012-04-08 Thread Jim Gibson
At 12:50 AM + 4/9/12, Vyacheslav wrote: I enabled RaiserError, then script die. ... my %attr = ( PrintError => 0, RaiseError => 1 ); Use: RaiseError => 0 instead so that your script will not raise an exception and die. Then check $dbh->err. -- To unsubscribe, e-mail: beginne

Re: foreach and next

2012-04-08 Thread Vyacheslav
I enabled RaiserError, then script die. ... my %attr = ( PrintError => 0, RaiseError => 1 ); my $dbh = DBI->connect($dsn, $user, $pass, \%attr); # or die "Can't connect to the DB: $DBI::errstr\n"; my $query = "SHOW DATABASES"; my $sth = $dbh->prepare($query) or die "Can't prepare SQL st

Re: foreach and next

2012-04-08 Thread Dr.Ruud
On 2012-04-08 17:10, Vyacheslav wrote: using eval helped me. You should not use exceptions for normal code flow. Read the DBI docs (perldoc DBI). If a failed connection must be an exception, set RaiseError to true. But if it isn't an exception, leave it false, and test $dbh->err (or the glob

Re: foreach and next

2012-04-08 Thread Shlomi Fish
Hi Vyacheslav, On Sun, 08 Apr 2012 15:10:06 + Vyacheslav wrote: > Thanks all. > > using eval helped me. > The problem with eval in Perl 5 is that it catches any and all thrown exceptions . I.e: by default, it doesn't do Object-Oriented exceptions like Java, Ruby, Python and other language

Re: foreach and next

2012-04-08 Thread Vyacheslav
Thanks all. using eval helped me. 08.04.2012 09:43, Shlomi Fish пишет: Hi Vyacheslav, On Sun, 08 Apr 2012 06:12:53 + Vyacheslav wrote: Hello all. My english bad and i have a problem. I am connected to databases in a cycle foreach and the script die, if one of database is not available.

Re: foreach and next

2012-04-08 Thread Shlomi Fish
Hi Vyacheslav, On Sun, 08 Apr 2012 06:12:53 + Vyacheslav wrote: > Hello all. > My english bad and i have a problem. > > I am connected to databases in a cycle foreach and the script die, if > one of database is not available. > > #!/usr/bin/perl > > use strict; > use warnings; > use DBI;

Re: foreach and next

2012-04-08 Thread Binish A.R
"host $db - not ok"; } else {         print "host $db - ok"; }   http://www.gnome.org/friends/banners/associate.png"; alt="Become a Friend of GNOME" border="0" /> From: Vyacheslav To: beginners@perl.org Sent: Sund

foreach and next

2012-04-07 Thread Vyacheslav
Hello all. My english bad and i have a problem. I am connected to databases in a cycle foreach and the script die, if one of database is not available. #!/usr/bin/perl use strict; use warnings; use DBI; use DBD::mysql; foreach $db (&hostdb("$project")) { my $server = "$db"; my $dbname = "in