use strict; use warnings; use Data::Dumper; $Data::Dumper::Terse = 1; # Raw structures, no $VAR1 style names. # One hash, with a (hash) reference taken to it– my %stuff = ( somekey => "someval", o => "hai" ); my $stuff_ref = \%stuff; # reference literally *references* original. print "Same hash, two ways to access: $stuff{o} eq $stuff_ref->{o}\n"; # See the hash right now. print "Original hash: ", Dumper( $stuff_ref ); my $value = delete $stuff_ref->{o}; print "Hash after deleting key o: ", Dumper( $stuff_ref ); print "Print it directly (uninitialized now): o => ", $stuff_ref->{o}, $/; # Add a new dimension to the data– $stuff_ref->{new_key}{sub_key} = "new value"; # Give it a friend, old key/value, new position– $stuff_ref->{new_key}{o} = $value; print "Hash after moving stuff around: ", Dumper( $stuff_ref ); $stuff_ref->{as}{deep}{as}{you} = "please"; $stuff_ref->{as}{deep}{as}{array_ref} = [ "one", "two" ]; $stuff_ref->{subroutine} = sub { print "OHAI!\n" }; $stuff_ref->{fancy_data} = [ "one", { two => "is a hash(ref)" }, ["another","array"], "last" ]; print "Perl data structures are *flexible* ", Dumper( $stuff_ref ); print "Excecuting code ref through data..."; $stuff_ref->{subroutine}->();