On Wed, Oct 27, 2010 at 12:49:01PM +0200, HACKER Nora wrote:
> Hi,
> 
> Since I do not believe that my computer suddenly has lost the ability to 
> compare numbers correctly, I suppose there must be some mistake in my 
> following code. To cut a long story short, the below sub 
> 1.    connects to a db, 
> 2.    gets the number of datafiles used by this db,
> 3.    gets the names of these datafiles, 
> 4.    gets the number of datafiles for this db from the filesystem,
> 5.    checks whether all the db's datafiles' pathes are within the $dbdir 
> (from another function) 
> 6.    and finally compares whether the numbers of datafiles in the db and on 
> the filesystem equal. 
>       
> And this is exactly the point: They equal for one database that I run a test 
> against, but the logic says they differ!
> 
> CODE:

>     ### 2 ###
>     # Anzahl der Datafiles in der DB (View DBA_DATA_FILES)
>     my $sql = "select count(*) from dba_data_files"; # SQL-Statement
>     my $sth = $dbh->prepare($sql); # Ausführung vorbereiten
>     my $anz_dbf_db = $dbh->selectcol_arrayref($sth); # holt alle Inhalte der 
> 1. Spalte in eine Array-REFERNZ!!!
>     $sth->finish();
>     if ( ! @$anz_dbf_db ) { # Array-REFERENZ!!!, Error, wenn DB nicht gelesen 
> werden kann
>         LOGWARN("$fnc - Datenbank konnte nicht gelesen werden: 
> $DBI::errstr\n");
>         $rcs { "$fnc" } = (1);
>     }
>     DEBUG("$fnc - Anzahl Datafiles aus DB: @$anz_dbf_db\n");

>     ### 6 ###
>     if ( @$anz_dbf_db != $anz_dbf_fs ) { # wenn Anzahl der Datafiles ungleich 
>         <-- ERROR HERE!
>         DEBUG("$fnc - vgl. @$anz_dbf_db != $anz_dbf_fs\n");
>         my @dbfs_diff;
>         if ( @$anz_dbf_db > $anz_dbf_fs ) { # mehr Datafiles in der DB als im 
> FS
>             LOGWARN("$fnc - ACHTUNG! Mehr Datafiles in der Datenbank 
> (@$anz_dbf_db) als im Filesystem ($anz_dbf_fs)!\n");
>             @dbfs_diff = grep 'MISSING', @$names_dbf_db;
>         } elsif ( @$anz_dbf_db < $anz_dbf_fs ) { # mehr Datafiles im FS als 
> in der DB
>             DEBUG("$fnc - vgl. @$anz_dbf_db < $anz_dbf_fs\n");
>             LOGWARN("$fnc - ACHTUNG! Mehr Datafiles im Filesystem 
> ($anz_dbf_fs) als in der Datenbank (@$anz_dbf_db)!\n");
>             foreach my $dbf_fs ( @dbfs_fs ) {
>                 if ( ! grep /$dbf_fs/, @$names_dbf_db ) {
>                     DEBUG("$fnc - DBF $dbf_fs matcht nicht mit DB.\n");
>                     push @dbfs_diff, $dbf_fs;
>                 }
>             }
>         } else {
>             INFO("$fnc - Anzahl Datafiles in Datenbank und Filesystem 
> ident.\n");
>         }
>         if ( @dbfs_diff ) {
>             LOGWARN("$fnc - Fehlende(s) Datafile(s): @dbfs_diff\n");
>         }
>         $rcs { "$fnc" } = (1);
>     }
> }
> 
> OUTPUT:
> 
> 2010/10/27 12:29:15 main::checkDatafiles - Anzahl Datafiles aus DB: 141
> 2010/10/27 12:29:15 main::checkDatafiles - Anzahl Datafiles im Filesystem: 141
> 2010/10/27 12:29:15 main::checkDatafiles - vgl. 141 != 141
> 2010/10/27 12:29:15 main::checkDatafiles - vgl. 141 < 141
> 2010/10/27 12:29:15 main::checkDatafiles - ACHTUNG! Mehr Datafiles im 
> Filesystem (141) als in der Datenbank (141)!

The problem here is to do with $anz_dbf_db.

You have correctly noted that this is an array reference.  To print in out you
have used "@$anz_dbf_db", which has printed the elements of the array,
separated by spaces.  This has shown you that there is one element of the
array, 141.

However, when using the array in a comparison, you have used @$anz_dbf_db
again, but this time in scalar context.  Here, you have asked for the number
of elements in the array, which is one.  You can test this by adding
DEBUG(scalar @$anz_dbf_db);  This is why the comparison is failing - 1 != 141.

So you should really be testing against $anz_dbf_db->[0] in your comparison.
Or better yet, in section two you should make $anz_dbf_db the actual number
you are looking for, rather than the array ref you are getting back.

> I hope that the sense of my output can be understood, even if it is not in 
> English...

Ich glaube dass alle verstehen Perl.

-- 
Paul Johnson - p...@pjcj.net
http://www.pjcj.net

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to