Hi all,

Is it possible to read the output of SQLPLUS (Oracle) directly into a hash array?  I
don't have DBI installed so this is not an option.  Currently, I am dumping the data
to a spool file, then reading the file into the hash.  I'd like to skip the file I/O
step if possible.


#--- beginning of script

#!/usr/bin/perl -w 
use strict;
my $f1 = "";
my $f2 = "";
my $oraId = "mylogid";
my $oraPw = "mypasswd";
my $spoolFile = "$0.tmp";
my $queryFile = "myscript.sql";
my $sql = "select fieldA, fieldB from mytable;\n";

open  QUERY, ">$queryFile" or die "Cannot create SQL script: $!\n";
print QUERY $sql;
close QUERY;

open  ORA, "| sqlplus -s $oraId/$oraPw \@myscript > $spoolFile" or die "Cannot pipe
to sqlplus: $!\n";
close ORA;

open SPOOL, "<$spoolFile" or die "Cannot open spool file: $!\n";

while (chomp(my $line = <SPOOL>) ) {
   last if (eof(SPOOL));
   $f1 = $f2 = "";
   next if ((!defined $line) || $line eq "" );
   ($f1, $f2) = split /\s*/, $line;
   # I expect $f1 to be any single alpha character, $f2 a number
   next unless ($f1 =~ /^[A-Z]$/ && $f2 =~ /\d/);
   $myarray{"$f1"} = $f2;
}
close SPOOL;
#--- end of script

Thanks in advance, 

Jeff

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to