in reply to (jeffa) Re: Multiple Data Selections per Field in CGI
in thread Multiple Data Selections per Field in CGI

If the key exists, then is the value a scalar, or is it an array? If it's the first time the key is encountered, then the value is simply a scalar. The second time the key is encountered, it's still a scalar. The value needs to be converted to an array, and then the new value is added. Each time after that, simply push the new value to the already existing array:

You could also do this quite nicely with a tie:

package Quantum::Heisenberg; sub TIESCALAR { bless [], $_[0] } sub STORE { push @{$_[0]}, $_[1] } sub FETCH { my $self = shift; $self->[int rand @$self]; } 1;

Changing the FETCH method to do what you'd expect is left as an exercise for the reader ;)

Tony