FutureBoyNil has asked for the wisdom of the Perl Monks concerning the following question:
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().
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: return Both ARRAY and SCALAR
by jhourcle (Prior) on May 01, 2009 at 13:25 UTC | |
|
Re: return Both ARRAY and SCALAR
by almut (Canon) on May 01, 2009 at 13:37 UTC | |
|
Re: return Both ARRAY and SCALAR
by JavaFan (Canon) on May 01, 2009 at 13:56 UTC | |
by FutureBoyNil (Initiate) on May 07, 2009 at 14:45 UTC | |
|
Re: return Both ARRAY and SCALAR
by Mutant (Priest) on May 01, 2009 at 13:34 UTC |