On Friday, July 26, 2002, at 08:04 , Connie Chan wrote:

> Would anyone tell me how to do something like this ?
>
> sub something
> {    my (%hash, %hash2, @array) = @_;
>         [......]
>     return (%result)
> }
>
> my %restult = something ( %hash, %hash2, @array);

back to basics - notice that the means to pass
things into a function is the @_ - which is a
list - one clearly will not be able to pass in
multiple lists and know where one stops and
the next one begins.

The solution then is to pass a reference to
each 'complex data type':

        sub something {
                my ($first_hash_ref, $second_hash_ref, $array_ref) = @_;
                ....
        }

and call it in the form

        my %restult = something ( \%hash, \%hash2, \@array);

or make the rule -

        only the last argument can be a list structure


        sub something {
                my ($first_ref, $second_ref, @last_array) = @_;
                ....
        }

and call it in the similar form

        my %restult = something ( \%hash, \%hash2, @array);

The same holds true on the back side of the game,
since one can not do

        my (@good_things, @bad_things) = fix(@list);

but one could do

        my ($goodies, $baddies ) = fix(@list);

        foreach (@$goodies) {
                .....
        }

        foreach (@$baddies) {
                .....
        }

ciao
drieux

---


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to