On 08/01/2006 08:13 AM, Dr. Claus-Peter Becke wrote:
databaserequest_noun($col, $table, $case) is a self written function based on the dbi manual's proposals. here's the code:

sub databaserequest_noun {
my ($col,$table,$case) = @_;
my $database = "lexikon";
my $hostname = "localhost";
my $dsn  = "DBI:mysql:database=$database; host=$hostname";
my $user = "myusername"; my $pass = "mypassword";
my $dbh = DBI::->connect( $dsn, $user, $pass,
                 { 'RaiseError' => 1, 'AutoCommit' => 1 } )
                     or die DBI::errstr;
my $sql = ("SELECT $col FROM $table where $col LIKE '%$Q::lexicalentry%'
       AND case LIKE '%$Q::case%'");
my $sth = $dbh->prepare($sql)
                 or die $dbh->errstr;
$sth->execute()
         or die $sth->errstr;

while (@row = $sth->fetchrow_array ) {
   print @row;
   print $q->br;
   }

$sth->finish;
$dbh->disconnect;

HERE

}
maybe anybody detects the reason why the return value becomes 1 after having assigned databaesrequest_noun to a new variable which shall be used inside an if-clause.

A Perl function returns the result value of the last command in that function; since $dbh->disconnect is the last command in the function, and since $dbh->disconnect returns '1,' the function databaserequest_noun() returns '1.'

> print @row returns a string value as required.
>

"Print @row" /displays/ a string value; it returns nothing.

The return value of a function and print statements in that function have nothing to do with one another.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to