sierrathedog04 has asked for the wisdom of the Perl Monks concerning the following question:
If an object member function returns a string in scalar context then should it behave similarly in interpolative context?
It would seem logical to me that it should, yet my experience is that it does not, e.g.:
my $parser = new XML::DOM::Parser; my $doc = $parser->parse("<hello></hello>"); my $root = $doc->getFirstChild; my $rootName = $root->getNodeName; print $root->getNodeName . "\n"; # prints 'hello' in scalar context print "$root->getNodeName\n"; # prints gibberish in interpolative cont +ext
Why the difference? Is this a design flaw in Perl, or am I misunderstanding what is going on?
Shouldn't the scalar return value of the getNodeName member function appear in both scalar and interpolative context?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unusual Behavior in Interpolative Context
by btrott (Parson) on Feb 01, 2001 at 01:32 UTC | |
by sierrathedog04 (Hermit) on Feb 01, 2001 at 20:00 UTC | |
by chromatic (Archbishop) on Feb 04, 2001 at 11:01 UTC |