in reply to Scalar ref acting as simulatenous hash and array?

Is there any reason why you can't just have a function available for the inexperienced devs to convert the recieved array into a hash if they aren't happy with using an array?
eg
my $obj_array = do_stuff_from_my_module(); my $obj_hash = convert_masems_array_to_a_hash($obj_array); #then the valid code options would be my $name = $obj_array->[2]; # Assume name is the 3rd element # # OR!!! # my $name = $obj_hash->{ name };

Your other option could be to use a pseudo hash but I haven't really used them myself for anything significant.

Replies are listed 'Best First'.
Re: Re: Scalar ref acting as simulatenous hash and array?
by Hofmator (Curate) on Oct 19, 2001 at 19:14 UTC

    Well, in that case I think it's easier to provide two functions, one which returns the array and one which returns the hash.

    Another idea would be to provide some global way of configuring the module into either returning hashes or arrays.

    -- Hofmator