narse has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; sub make_hashref {{ foo => 'bar', }} sub make_hashref2 {{ boo => 'too', %{ make_hashref() }, }} sub make_hashref3 {{ %{ make_hashref() }, boo => 'too', }} print Dumper make_hashref(); print Dumper make_hashref2(); print Dumper make_hashref3();
But the 3rd one is no longer a reference:$VAR1 = { 'foo' => 'bar' }; $VAR1 = { 'foo' => 'bar', 'boo' => 'too' };
As far as I know, there should be no difference between 2 and 3. I find that if I explicitly `return' the hashref in example 3, it functions properly. Is there a subtlety that I am missing? Is this a bug?$VAR1 = 'foo'; $VAR2 = 'bar'; $VAR3 = 'boo'; $VAR4 = 'too';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Constant Hashref Strangeness
by simonm (Vicar) on Dec 12, 2004 at 20:54 UTC | |
|
Re: Constant Hashref Strangeness
by Errto (Vicar) on Dec 13, 2004 at 04:53 UTC | |
|
Re: Constant Hashref Strangeness
by Thilosophy (Curate) on Dec 13, 2004 at 02:01 UTC |