dreadpiratepeter has asked for the wisdom of the Perl Monks concerning the following question:
I was under the impression that this code will not run. Specifically, because of the array deref. $hash{first} should return undef, and I did not think you could dereference an undefined value and magically get an array reference, but the code runs. I had always used:#!/usr/local/bin/perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Indent = 1; my @array1 = qw{rose orange green}; my @array2 = qw{blue red}; my %hash; push @{$hash{first}}, \@array1, \@array2; print Dumper \%hash;
I am sure (in my own mind, at least) that I would get run-time errors if I left out the initialization.$hash{first} ||= []; push @{ $hash{first} },'foo';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: autovivication gonna make me lose my mind
by kyle (Abbot) on Sep 16, 2008 at 15:52 UTC | |
by dreadpiratepeter (Priest) on Sep 16, 2008 at 16:06 UTC | |
by ig (Vicar) on Nov 04, 2008 at 14:06 UTC | |
|
Re: autovivication gonna make me lose my mind
by Fletch (Bishop) on Sep 16, 2008 at 15:42 UTC | |
|
Re: autovivication gonna make me lose my mind
by tilly (Archbishop) on Sep 16, 2008 at 16:51 UTC |