#!/usr/bin/perl use strict; use warnings; use DBI; my $var1 = "dbname"; #Database Name my $var2 = "user"; #Username my $var3 = "pass"; #Password my $var4 = "select directory_path, keyword1, keyword2, keyword3 from load_instance where rule_id = '1'"; sub db_conn1 { $dbh = DBI -> connect("DBI:Oracle:".$var1,$var2,$var3) || die ("not connected:DBI::errstr"); my $sth = $dbh -> prepare($var4); $sth->execute(); while(@row=$sth->fetchrow_array()) #Fetch the number of rows { #returned by the query $values=$row[0]; print "@row\n"; } } ######db_conn1($var1,$var2,$var3,$var4); sub search_phrase { my ( $inFile, @phrases ) = @_; open my $inFH, q{<}, $inFile or die qq{open: $inFile: $!\n}; my $line; PHRASE: foreach my $phrase ( @phrases ) { my $rxPhrase = qr{\Q$phrase\E}; # keep reading down the file while ($line = <$inFH>) { # when one phrase matches, jump to the next next PHRASE if $line =~ /$rxPhrase/; } # end of file, and we haven't matched the last phrase } # We have just matched the last phrase. # The number we want is somewhere in $line. my ($number) = $line =~ /(\d+)/; return $number; } my $result = search_phrase(db_conn1($var1,$var2,$var3,$var4)); if (defined $result) { print "$result\n" } else { print "-1\n" }