The results of the function db_conn1 must be passed as arguments to the function search_phrase. But what i get is the results of the db_conn1 function and throws me an error, directory or path not found... but actually it does exists... this is true cuz when i run this function seperately it gives me the correct result... i actually stored the results of db_conn1 function's results in an array and passed it to the search_phrase function...

#!/usr/bin/perl #use strict; use warnings; use DBI; my $db_name = "dbname"; #Database Name my $user_name = "myuser"; #Username my $passwd = "passswd"; #Password my $sql_query = "select directory_path, keyword1, keyword2, keyword3 +from load_instance where rule_id = '1'"; sub db_conn1 { my $dbh = DBI -> connect("DBI:Oracle:".$db_name,$user_name,$passwd) || + die ("not connected:DBI::errstr"); my $sth = $dbh -> prepare($sql_query); $sth->execute(); while(my @row=$sth->fetchrow_array()) #Fetch the number of rows { #returned by the query my $values=$row[0]; print "@row\n"; } } my @newarray = db_conn1($db_name,$user_name,$passwd,$sql_quer); 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 return; } # 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)); my $result = &search_phrase('@newarray'); if (defined $result) { print "$result\n" } else { print "-1\n" }


Errors: -------

perl comb1.pl
/users/myuser1/merc/test.txt total rows rejected: reject: total reject +ed rows: open: @newarray: A file or directory in the path name does not exist.


Thanks.

In reply to Re^4: functions and arguments by mercuryshipz
in thread functions and arguments by mercuryshipz

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.