The last item that you pass to a perl subroutine can be a array or a 
hash, but none but the last, since oerl will greedy-match your arrays 
when you assign them in your subroutine.  The way around this is to pass 
them in by reference:

($rows, %results) = &Select($mytable, $where_f1, $compare1, $where_v1,
\@quick_check, \%field_values);

sub Select {
my($db_table, $where_field, $comparison, $where_value,$fieldlist_ref,
$values_ref) = @_;


# To access @fieldlist
my @fieldlist = @$fieldlist_ref;
my %values = %$values_ref;
......

return $rc, %table;
}


The same thing happens for return values ($rc, %table) works, but (%rc, 
%table) would not.  Returning by reference is a good solution here as 
well.

George


On Thursday, July 11, 2002, at 11:02 AM, rory oconnor wrote:

> Is it possible to pass a hash into a subroutine to be used as a local
> variable?  I'm trying to do this:
>
> ($rows, %results) = &Select($mytable, $where_f1, $compare1, $where_v1,
> @quick_check, %field_values);
>
> sub Select {
> my($db_table, $where_field, $comparison, $where_value,@fieldlist,
> %values) = @_;
>
> .....
>
> return $rc, %table;
> }
>
> and it's not working.  If I remove %field_values and the corresponfing
> reference, %values and use %field_values as a global varaible, it works
> fine.  I'm able to return a hash no problem, but sending one doesn't
> seem to work!
>
> Any help appreciated.
>
> Thanks,
> Rory
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
// George Schlossnagle
// Principal Consultant
// OmniTI, Inc          http://www.omniti.com
// (c) 240.460.5234   (e) [EMAIL PROTECTED]
// 1024D/1100A5A0  1370 F70A 9365 96C9 2F5E 56C2 B2B9 262F 1100 A5A0

Reply via email to