talexb has asked for the wisdom of the Perl Monks concerning the following question:
If I try running the following:
then I get the expected result:#!/usr/bin/perl -w use Data::Dumper; { my $hashref; $hashref->{'foo'} = "bar"; print Dumper($hashref); }
However, if I try to combined the my and the assignment on the same line, as in the following:[alex@home dev]$ perl -w hashref.pl $VAR1 = { 'foo' => 'bar' };
then Perl gives me an error:#!/usr/bin/perl -w use Data::Dumper; { my $hashref->{'foo'} = "bar"; print Dumper($hashref); }
This seems odd to me -- does this mean that there's a limit to what autovivification will do?[alex@home dev]$ perl -w hashref2.pl Can't use an undefined value as a HASH reference at hashref2.pl line 6 +.
The difference seems semantic to me. Please, pass me a clue by four.
Alex / talexb / Toronto
"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using an undefined value as a hashref
by itub (Priest) on Sep 09, 2005 at 21:13 UTC | |
by ikegami (Patriarch) on Sep 10, 2005 at 04:04 UTC | |
by phaylon (Curate) on Sep 10, 2005 at 20:13 UTC | |
by talexb (Chancellor) on Sep 09, 2005 at 21:16 UTC | |
|
Re: Using an undefined value as a hashref
by NetWallah (Canon) on Sep 09, 2005 at 21:44 UTC | |
|
Re: Using an undefined value as a hashref
by InfiniteLoop (Hermit) on Sep 09, 2005 at 21:00 UTC | |
by talexb (Chancellor) on Sep 09, 2005 at 21:10 UTC | |
|
Re: Using an undefined value as a hashref
by ambrus (Abbot) on Sep 09, 2005 at 21:58 UTC | |
|
Re: Using an undefined value as a hashref
by runrig (Abbot) on Sep 09, 2005 at 21:19 UTC | |
by QM (Parson) on Sep 09, 2005 at 21:51 UTC |