duyet has asked for the wisdom of the Perl Monks concerning the following question:
when exectuted:my $hash = {}; do_something( $hash ); print Dumper( $hash ); sub do_something { my $hash = shift; $hash = { a => 'alpha', b => 'beta', }; print Dumper( $hash ); }
but if using:{ 'a' => 'alpha', 'b' => 'beta' } {}
it shows:do_something_else( $hash ); print Dumper( $hash ); sub do_something_else { my $hash = shift; $hash->{g} = 'gamma'; $hash->{d} = 'delta'; print Dumper( $hash ); }
To me the initialization of $hash is the same in both subs, but apparently it is not. It's probably something very trivial, but i just miss it. Would you please explain why? TIA.{ 'd' => 'delta', 'g' => 'gamma' } { 'd' => 'delta', 'g' => 'gamma' }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: hash question
by GrandFather (Saint) on May 26, 2016 at 11:01 UTC | |
|
Re: hash question
by BrowserUk (Patriarch) on May 26, 2016 at 11:00 UTC | |
|
Re: hash question
by AnomalousMonk (Archbishop) on May 26, 2016 at 15:48 UTC | |
by duyet (Friar) on May 27, 2016 at 05:55 UTC | |
by andal (Hermit) on May 27, 2016 at 07:44 UTC | |
by soonix (Chancellor) on May 27, 2016 at 07:00 UTC | |
by AnomalousMonk (Archbishop) on May 27, 2016 at 16:12 UTC | |
|
Re: hash question
by AnomalousMonk (Archbishop) on May 27, 2016 at 18:41 UTC | |
by duyet (Friar) on Jun 03, 2016 at 12:57 UTC |