I'm creating a simple little thing to compare tables and rowcounts in a particular schema between two oracle databases.

Currently, I've got the hashes created using references and can look at the data, but I need to compare the hashes against each other. I wanted to do this in a new subroutine, but I'm confused on how to return the data so it can be used in another sub.
#!/usr/local/bin/perl -w use strict; use DBI; use Env; my @DB = ('ORACLE1','ORACLE2'); my $user = "user"; my $passwd = "passwd"; my $schema = "FOOBAR"; &query_databases(); sub query_databases { for (@DB) { my %dbs; my ($dbh,$sth,@TABLE_NAMES,$TABLE_NAME,$rowcount,%result); my $db = $_; my $DBHome = "/U01/oracle/ora817"; $ENV{"ORACLE_HOME"} = $DBHome; # Login to the database $dbh = DBI->connect("dbi:Oracle:$db",$user,$passwd,{AutoCommit => +0, RaiseError => 1}) || die("Oracle login FAILED, $DBI::errstr"); $sth = $dbh->prepare("select TABLE_NAME from dba_tables where owne +r=?"); $sth->execute( $schema ); while ( $TABLE_NAME = $sth->fetchrow_array ) { push(@TABLE_NAMES,$TABLE_NAME); } die $sth->errstr if $sth->err; for $TABLE_NAME ( @TABLE_NAMES ) { $sth = $dbh->prepare("select count(*) from $schema.$TABLE_NAME" +); $sth->execute; while ($rowcount = $sth->fetchrow_array ) { $dbs{$db}->{$TABLE_NAME} = $rowcount; } } # for my $key1 (@DB) { # print "Database is $key1\n"; # for my $key2 ( sort keys %{$dbs{$key1}} ) { # print "TABLE = $key2\trows = $dbs{$key1}->{$key2}\n"; # } # } $dbh->disconnect; } } sub do_compare { # ???????? }
I'm sure I've used inferior variable declaration and scope. Please be as harsh as needed.

In reply to References and passing data to a different sub. by bcole23

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.