Hello,

I'm having a shot at writing a module for the first.

I am experiencing some issues returning an array.

The code fragment  below is the bit I'm having issues with.  I know that
everything works as the commented print stmts work.  When I try to return the
value to the calling script I seem to be getting a count of the elements of the
array.

#
# sumSales($THIS_JULIAN)
#
sub sumSales{

     my $sth = $DBH->prepare("
          SELECT SUM(this), COUNT(that)
          FROM table_name
          WHERE keno_day = @_
          ") || die "Unable to prepare select: $!\n";

     $sth->execute();

     my (@row) = $sth->fetchrow_array();
     #print "@row\n";
     #my ($sales, $count) = @row;

     $sth->finish;
     #print "sumSales:\t$sales, $count\n\n";
     if (@row){return @row};
}

The sub is called like:

my @sales = myMod::sumSales(@arg)
     || die "Unable to complete sumSales routine: $!\n";
where @arg only has one element.

The doco about return says "The supplied expersion will be evaluated in the
context of the subroutine invocation.  That is, if the subroutine was called in
a scalar context , EXPR is also evaluated in a scalar context.  If the
subroutine was invoked in a list context then EXPR is also evaluated in a
listcontext and can return a list value."

I'm guessing that this is the problem but have no idea what it means...

Any help would be appreciated.

Thanks


john


Reply via email to