http://www.perlmonks.org?node_id=761281

FutureBoyNil has asked for the wisdom of the Perl Monks concerning the following question:

Good day honorable monks. I humbly come to these gates seeking enlightment. I want a function to return a variable with both SCALAR and ARRAY values. It works for regular functions:
sub XX{
	my $x = 'one'; #scalar value
	push(@{$x}, 'two'); #overload array
	push(@{$x}, 'three'); #overload array
	return $x;
}

my $y = XX(); # typecastable scalar!
print join(", ",$y, @{$y}); # prints "one, two, three"
But as soon as I make it a module, this behaviour dissapears! so:
use MYMOD;
my $x = MYMOD->new();

my $y = $x->XX(); # $y is SCALAR only...
The reason is that I wrote a standalone data parser, and, just like xml, a tag can have multiple ocurrences, thus it is not guaranteed to be unique, but it could be. For now I use get_value() and get_values().